-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additional handling for email delimiters in roadmap feature and unit …
…tests
- Loading branch information
Showing
5 changed files
with
97 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { roadmapService } from '@/services'; | ||
import { appAxios } from '@/services/interceptors'; | ||
|
||
vi.mock('vue-router', () => ({ | ||
useRouter: () => ({ | ||
push: vi.fn() | ||
}) | ||
})); | ||
|
||
const PATH = 'roadmap'; | ||
// const getSpy = vi.fn(); | ||
const putSpy = vi.fn(); | ||
|
||
vi.mock('@/services/interceptors'); | ||
vi.mocked(appAxios).mockReturnValue({ | ||
// get: getSpy, | ||
put: putSpy | ||
} as any); | ||
|
||
const testAddressString = ['test.1.address@test.bc.ca', 'testAddress2@test.com', 'test3Email@test.ca']; | ||
const unformattedEmailList = 'test.1.address@test.bc.ca, testAddress2@test.com,; test3Email@test.ca'; | ||
const bccField = 'addressTest2@test.com'; | ||
|
||
const testData = { | ||
activityId: '123-123', | ||
emailData: { | ||
from: 'fromAddress@test.com', | ||
to: testAddressString, | ||
bcc: [bccField], | ||
subject: 'Here is your housing project Permit Roadmap', | ||
bodyType: 'text', | ||
body: 'testText' | ||
} | ||
}; | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
describe('roadmapService test', () => { | ||
it('sends email when called with right params', async () => { | ||
await roadmapService.send(testData.activityId, ['testSelectedFileIds'], testData.emailData); | ||
|
||
expect(putSpy).toHaveBeenCalledTimes(1); | ||
expect(putSpy).toHaveBeenCalledWith(PATH, { | ||
activityId: testData.activityId, | ||
selectedFileIds: ['testSelectedFileIds'], | ||
emailData: expect.objectContaining({ | ||
to: ['test.1.address@test.bc.ca', 'testAddress2@test.com', 'test3Email@test.ca'], | ||
bcc: [bccField] | ||
}) | ||
}); | ||
expect(putSpy).not.toHaveBeenCalledWith(expect.objectContaining({ cc: expect.anything() })); | ||
}); | ||
|
||
it('formats improper to/cc/bcc fields', async () => { | ||
const modifiedEmail = { | ||
...testData.emailData, | ||
to: unformattedEmailList, | ||
cc: unformattedEmailList, | ||
bcc: unformattedEmailList | ||
}; | ||
|
||
// @ts-expect-error: testing if email object it not proper type | ||
await roadmapService.send(testData.activityId, ['testSelectedFileIds'], modifiedEmail); | ||
|
||
expect(putSpy).toHaveBeenCalledTimes(1); | ||
expect(putSpy).toHaveBeenCalledWith( | ||
PATH, | ||
expect.objectContaining({ | ||
emailData: expect.objectContaining({ | ||
to: ['test.1.address@test.bc.ca', 'testAddress2@test.com', 'test3Email@test.ca'], | ||
cc: ['test.1.address@test.bc.ca', 'testAddress2@test.com', 'test3Email@test.ca'], | ||
bcc: ['test.1.address@test.bc.ca', 'testAddress2@test.com', 'test3Email@test.ca'] | ||
}) | ||
}) | ||
); | ||
}); | ||
}); |