-
Notifications
You must be signed in to change notification settings - Fork 4
[MKT-737]:feat/integrate Klaviyo subscription when creating Send links #945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2d410ad
feat: send tracking service
jaaaaavier 1e2b1cb
feat: add coverage for newsletter
jaaaaavier 57ddfbe
Update send.usecase.spec.ts
jaaaaavier 8172ae3
Update tests to be aligned with the rest of the files-
jaaaaavier 815c4e8
remove unused sendLink variable in usecase specs
jaaaaavier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,104 @@ | ||
| import { Test, type TestingModule } from '@nestjs/testing'; | ||
| import { NewsletterService } from './index'; | ||
| import { ConfigService } from '@nestjs/config'; | ||
| import { HttpClient } from '../http/http.service'; | ||
| import { createMock } from '@golevelup/ts-jest'; | ||
|
|
||
| describe('NewsletterService', () => { | ||
| let service: NewsletterService; | ||
| let configService: ConfigService; | ||
| let httpClient: HttpClient; | ||
|
|
||
| beforeEach(async () => { | ||
| const module: TestingModule = await Test.createTestingModule({ | ||
| providers: [NewsletterService], | ||
| }) | ||
| .useMocker(createMock) | ||
| .compile(); | ||
|
|
||
| service = module.get<NewsletterService>(NewsletterService); | ||
| configService = module.get<ConfigService>(ConfigService); | ||
| httpClient = module.get<HttpClient>(HttpClient); | ||
|
|
||
| jest.spyOn(configService, 'get').mockImplementation((key: string) => { | ||
| if (key === 'newsletter.listId') return 'defaultListId'; | ||
| if (key === 'newsletter.apiKey') return 'testApiKey'; | ||
| if (key === 'klaviyo.baseUrl') return 'https://a.klaviyo.com/api/'; | ||
| return null; | ||
| }); | ||
| }); | ||
|
|
||
| it('When instantiated, then it should be defined', () => { | ||
| expect(service).toBeDefined(); | ||
| }); | ||
|
|
||
| describe('subscribe', () => { | ||
| it('When a listId is not provided, then it should subscribe the user using the default listId', async () => { | ||
| const email = 'test@example.com'; | ||
| jest.spyOn(httpClient, 'post').mockResolvedValueOnce({ | ||
| data: { data: { id: 'prof_123' } }, | ||
| } as any); | ||
| jest.spyOn(httpClient, 'post').mockResolvedValueOnce({} as any); | ||
|
|
||
| await service.subscribe(email); | ||
|
|
||
| expect(httpClient.post).toHaveBeenNthCalledWith( | ||
| 1, | ||
| 'https://a.klaviyo.com/api/profiles/', | ||
| { | ||
| data: { | ||
| type: 'profile', | ||
| attributes: { email }, | ||
| }, | ||
| }, | ||
| { | ||
| headers: { | ||
| Accept: 'application/json', | ||
| Authorization: 'Klaviyo-API-Key testApiKey', | ||
| 'Content-Type': 'application/json', | ||
| revision: '2024-10-15', | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| expect(httpClient.post).toHaveBeenNthCalledWith( | ||
| 2, | ||
| 'https://a.klaviyo.com/api/lists/defaultListId/relationships/profiles/', | ||
| { data: [{ type: 'profile', id: 'prof_123' }] }, | ||
| { | ||
| headers: { | ||
| Accept: 'application/json', | ||
| Authorization: 'Klaviyo-API-Key testApiKey', | ||
| 'Content-Type': 'application/json', | ||
| revision: '2024-10-15', | ||
| }, | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| it('When a listId is provided, then it should subscribe the user using that listId', async () => { | ||
| const email = 'test@example.com'; | ||
| const providedListId = 'providedListId'; | ||
| jest.spyOn(httpClient, 'post').mockResolvedValueOnce({ | ||
| data: { data: { id: 'prof_123' } }, | ||
| } as any); | ||
| jest.spyOn(httpClient, 'post').mockResolvedValueOnce({} as any); | ||
|
|
||
| await service.subscribe(email, providedListId); | ||
|
|
||
| expect(httpClient.post).toHaveBeenNthCalledWith( | ||
| 1, | ||
| 'https://a.klaviyo.com/api/profiles/', | ||
| expect.any(Object), | ||
| expect.any(Object), | ||
| ); | ||
|
|
||
| expect(httpClient.post).toHaveBeenNthCalledWith( | ||
| 2, | ||
| 'https://a.klaviyo.com/api/lists/providedListId/relationships/profiles/', | ||
| { data: [{ type: 'profile', id: 'prof_123' }] }, | ||
| expect.any(Object), | ||
| ); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.