-
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 branch 'feat-implement-pagination-on-findAllTeamMembers-endpoin…
…t' of https://github.com/akinwalexander/hng_boilerplate_nestjs into feat-implement-pagination-on-findAllTeamMembers-endpoint
- Loading branch information
Showing
13 changed files
with
140 additions
and
20 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
8 changes: 8 additions & 0 deletions
8
src/modules/newsletter-subscription/dto/unsubscribe-newsletter.dto.ts
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,8 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsEmail } from 'class-validator'; | ||
|
||
export class UnsubscribeNewsletterDto { | ||
@ApiProperty({ description: 'Email of the user to unsubscribe' }) | ||
@IsEmail() | ||
email: string; | ||
} |
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 |
---|---|---|
|
@@ -146,4 +146,47 @@ describe('NewsletterService', () => { | |
await expect(service.restore(id)).rejects.toThrow(NotFoundException); | ||
}); | ||
}); | ||
|
||
describe('unsubscribe', () => { | ||
it('should successfully unsubscribe a user', async () => { | ||
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 => | ||
({ | ||
...sub, | ||
isUnsubscribed: true, | ||
email: sub.email, | ||
deletedAt: sub.deletedAt || new Date(), | ||
id: sub.id, | ||
created_at: sub.created_at || new Date(), | ||
updated_at: new Date(), | ||
}) as NewsletterSubscription | ||
); | ||
|
||
const result = await service.unsubscribe(email); | ||
expect(result).toEqual({ message: `Email ${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`) | ||
); | ||
|
||
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
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