Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mannipje committed Oct 4, 2024
1 parent 9c2dc07 commit f6ba10b
Showing 1 changed file with 28 additions and 37 deletions.
65 changes: 28 additions & 37 deletions libs/api/domains/email-signup/src/lib/emailSignup.resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,28 @@ describe('emailSignupResolver', () => {
})

describe('subscribeToCampaignMonitor', () => {
const testEmailSlice: EmailSignup = {
id: '345',
title: '',
description: '',
configuration: {
signupUrl: 'test.is',
},
formFields: [
{
id: '1',
options: [],
placeholder: '',
required: true,
title: '',
type: 'email',
name: 'EmailAddress',
emailConfig: {},
},
],
signupType: 'campaign monitor',
translations: {},
}
const testInput: EmailSignupInput = {
signupID: '345',
inputFields: [
Expand All @@ -192,21 +214,13 @@ describe('emailSignupResolver', () => {
},
],
}
it('should handle invalid email', async () => {
jest.spyOn(axios, 'post').mockImplementation(() => {
return Promise.resolve({
data: 0,
})
})

const result = await emailSignupResolver.emailSignupSubscription(
testInput,
)

expect(result?.subscribed).toBe(false)
})

it('should handle errors from the subscription API', async () => {
jest
.spyOn(cmsContentfulService, 'getEmailSignup')
.mockImplementation(({ id }) =>
Promise.resolve(id === '345' ? testEmailSlice : null),
)
jest.spyOn(axios, 'post').mockImplementation(() => {
return Promise.reject(new Error('Network error'))
})
Expand All @@ -219,36 +233,13 @@ describe('emailSignupResolver', () => {
})

it('should get a successful response if input is valid', async () => {
const testEmailSlice: EmailSignup = {
id: '345',
title: '',
description: '',
configuration: {
signupUrl: 'test.is',
},
formFields: [
{
id: '1',
options: [],
placeholder: '',
required: true,
title: '',
type: 'email',
name: 'EmailAddress',
emailConfig: {},
},
],
signupType: 'campaign monitor',
translations: {},
}

jest
.spyOn(cmsContentfulService, 'getEmailSignup')
.mockImplementation(({ id }) =>
Promise.resolve(id === '345' ? testEmailSlice : null),
)

jest.spyOn(axios, 'post').mockImplementation((url, data) => {
jest.spyOn(axios, 'post').mockImplementation((_url, data) => {
const EmailAddress = (data as { EmailAddress: string }).EmailAddress

return Promise.resolve({
Expand Down

0 comments on commit f6ba10b

Please sign in to comment.