Skip to content

Commit

Permalink
fix mailchimp test
Browse files Browse the repository at this point in the history
  • Loading branch information
nomadbitcoin committed Sep 25, 2024
1 parent 093bbee commit a0f10ce
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions functions/test/lib/mailchimp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]",
firstName: "John",
lastName: "Doe",
user_email: '[email protected]',
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: "[email protected]",
expect(mailchimp.lists.addListMember).toHaveBeenCalledWith('cohort_list_id', {
email_address: '[email protected]',
status: 'subscribed',
})
expect(mailchimp.lists.addListMember).toHaveBeenCalledWith('course_list_id', {
email_address: '[email protected]',
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: "[email protected]",
firstName: "John",
lastName: "Doe",
email: '[email protected]',
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: "[email protected]",
status: "subscribed",
expect(mailchimp.lists.addListMember).toHaveBeenCalledWith('b578d43584', {
email_address: '[email protected]',
status: 'subscribed',
merge_fields: {
EMAIL: "[email protected]",
FIRSTNAME: "John",
LASTNAME: "Doe",
NAME: 'John',
WALLET: '0x1234567890abcdef',
},
})
})
})
})

0 comments on commit a0f10ce

Please sign in to comment.