Skip to content

Commit c181408

Browse files
committed
Update src/pages/api/newsletter contact and _email unit tests to reflect changes made while implementing E2E tests
1 parent a2600e6 commit c181408

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

src/pages/api/newsletter/__tests__/_confirm.spec.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,12 @@ describe('Newsletter Confirmation API - GET /api/newsletter/confirm', () => {
119119
expect(supabaseFromMock).toHaveBeenCalledWith('consent_records')
120120
expect(supabaseQueryBuilder.update).toHaveBeenCalledWith({ verified: true })
121121

122-
// Verify welcome email was sent
123-
expect(mockSendWelcomeEmail).toHaveBeenCalledWith('test@example.com', 'John')
122+
// Verify welcome email was sent (force mock disabled by default)
123+
expect(mockSendWelcomeEmail).toHaveBeenCalledWith(
124+
'test@example.com',
125+
'John',
126+
expect.objectContaining({ forceMockResend: false }),
127+
)
124128

125129
expect(mockSubscribeToConvertKit).toHaveBeenCalledWith(
126130
expect.objectContaining({ email: 'test@example.com' }),
@@ -142,9 +146,10 @@ describe('Newsletter Confirmation API - GET /api/newsletter/confirm', () => {
142146
const response = await GET(createRequestContext('http://localhost/api/newsletter/confirm?token=expired-token'))
143147
const body = await response.json()
144148

145-
expect(response.status).toBe(400)
146-
expect(body.error).toBeDefined()
147-
expect(body.error.message).toContain('expired')
149+
expect(response.status).toBe(200)
150+
expect(body.success).toBe(false)
151+
expect(body.status).toBe('expired')
152+
expect(body.message).toContain('expired')
148153
})
149154

150155
it('should handle subscription without firstName', async () => {
@@ -166,7 +171,11 @@ describe('Newsletter Confirmation API - GET /api/newsletter/confirm', () => {
166171

167172
expect(response.status).toBe(200)
168173
expect(data.success).toBe(true)
169-
expect(mockSendWelcomeEmail).toHaveBeenCalledWith('test@example.com', undefined)
174+
expect(mockSendWelcomeEmail).toHaveBeenCalledWith(
175+
'test@example.com',
176+
undefined,
177+
expect.objectContaining({ forceMockResend: false }),
178+
)
170179
})
171180

172181
it('should handle subscription without ipAddress', async () => {

src/pages/api/newsletter/__tests__/_index.spec.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ describe('Newsletter API - POST /api/newsletter', () => {
104104
firstName: 'John',
105105
}),
106106
)
107-
expect(mockSendConfirmationEmail).toHaveBeenCalledWith('test@example.com', 'test-token-123', 'John')
107+
expect(mockSendConfirmationEmail).toHaveBeenCalledWith(
108+
'test@example.com',
109+
'test-token-123',
110+
'John',
111+
expect.objectContaining({ forceMockResend: false }),
112+
)
108113
})
109114

110115
it('should reject subscription without email', async () => {
@@ -219,7 +224,12 @@ describe('Newsletter API - POST /api/newsletter', () => {
219224

220225
expect(response.status).toBe(200)
221226
expect(data.success).toBe(true)
222-
expect(mockSendConfirmationEmail).toHaveBeenCalledWith('test@example.com', 'test-token-123', undefined)
227+
expect(mockSendConfirmationEmail).toHaveBeenCalledWith(
228+
'test@example.com',
229+
'test-token-123',
230+
undefined,
231+
expect.objectContaining({ forceMockResend: false }),
232+
)
223233
})
224234

225235
it('should handle service errors gracefully', async () => {

0 commit comments

Comments
 (0)