From a0f10ce3cfc0efed79d3e47986fa0b2033f7d7b0 Mon Sep 17 00:00:00 2001 From: Yan Luiz Date: Wed, 25 Sep 2024 18:23:43 -0300 Subject: [PATCH] fix mailchimp test --- functions/test/lib/mailchimp.test.js | 48 +++++++++++++++------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/functions/test/lib/mailchimp.test.js b/functions/test/lib/mailchimp.test.js index 16c9b66d..1904d4e5 100644 --- a/functions/test/lib/mailchimp.test.js +++ b/functions/test/lib/mailchimp.test.js @@ -5,56 +5,58 @@ jest.mock('@mailchimp/mailchimp_marketing', () => ({ setConfig: jest.fn(), lists: { addListMember: jest.fn(), - } + }, })) -describe('add User to list', function() { +describe('add User to list', function () { beforeEach(() => { mailchimp.lists.addListMember.mockClear() }) - it("Should add users to list correctly", async () => { + it('Should add users to list correctly', async () => { const emailData = { - user_email: "example@gmail.com", - firstName: "John", - lastName: "Doe", + user_email: 'example@gmail.com', + firstName: 'John', + lastName: 'Doe', params: { - cohort: "test", - course: "test", + cohort: 'cohort_list_id', + course: 'course_list_id', }, } await addUserToList(emailData) expect(mailchimp.setConfig).toHaveBeenCalledTimes(1) - expect(mailchimp.lists.addListMember).toHaveBeenCalledWith("test", { - email_address: "example@gmail.com", + expect(mailchimp.lists.addListMember).toHaveBeenCalledWith('cohort_list_id', { + email_address: 'example@gmail.com', + status: 'subscribed', + }) + expect(mailchimp.lists.addListMember).toHaveBeenCalledWith('course_list_id', { + email_address: 'example@gmail.com', status: 'subscribed', }) - expect(mailchimp.lists.addListMember).toHaveBeenCalledTimes(2) }) }) -describe("create user in mailchimp", () => { +describe('create user in mailchimp', () => { beforeEach(() => { mailchimp.lists.addListMember.mockClear() }) const user = { - email: "test@gmail.com", - firstName: "John", - lastName: "Doe", + email: 'test@gmail.com', + name: 'John', + wallet_address: '0x1234567890abcdef', } - it("Should create user in mailchimp", async () => { + it('Should create user in mailchimp', async () => { await createUser(user) - expect(mailchimp.lists.addListMember).toHaveBeenCalledWith("b578d43584", { - email_address: "test@gmail.com", - status: "subscribed", + expect(mailchimp.lists.addListMember).toHaveBeenCalledWith('b578d43584', { + email_address: 'test@gmail.com', + status: 'subscribed', merge_fields: { - EMAIL: "test@gmail.com", - FIRSTNAME: "John", - LASTNAME: "Doe", + NAME: 'John', + WALLET: '0x1234567890abcdef', }, }) }) -}) \ No newline at end of file +})