-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1358 from hngprojects/feat/unsubscribe-newsletter
refactor(http): rename statusCode to status_code and prevent email exposure in response
- Loading branch information
Showing
4 changed files
with
7 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,9 +152,7 @@ describe('NewsletterService', () => { | |
const email = '[email protected]'; | ||
const mockSubscription = { id: '1', email, isUnsubscribed: false } as NewsletterSubscription; | ||
|
||
// Mock `findOne` to return a subscribed user | ||
jest.spyOn(repository, 'findOne').mockResolvedValue(mockSubscription); | ||
// Mock `save` to return updated object | ||
jest.spyOn(repository, 'save').mockImplementation( | ||
async sub => | ||
({ | ||
|
@@ -169,21 +167,18 @@ describe('NewsletterService', () => { | |
); | ||
|
||
const result = await service.unsubscribe(email); | ||
expect(result).toEqual({ message: `Email ${email} has been unsubscribed successfully` }); | ||
expect(result).toEqual({ message: 'Email has been unsubscribed successfully' }); | ||
|
||
// Ensure `isUnsubscribed` was updated | ||
expect(repository.save).toHaveBeenCalledWith(expect.objectContaining({ isUnsubscribed: true })); | ||
}); | ||
|
||
it('should throw NotFoundException if email is not found', async () => { | ||
const email = '[email protected]'; | ||
|
||
// Mock `findOne` to return null | ||
jest.spyOn(repository, 'findOne').mockResolvedValue(null); | ||
|
||
// Expecting an error | ||
await expect(service.unsubscribe(email)).rejects.toThrow( | ||
new NotFoundException(`Email ${email} not found in the subscription list`) | ||
new NotFoundException('Email not found in the subscription list') | ||
); | ||
|
||
expect(repository.findOne).toHaveBeenCalledWith({ where: { email } }); | ||
|
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