-
Notifications
You must be signed in to change notification settings - Fork 192
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
feat: Implemented pagination to getAllBilling Plans Endpoint #1316
Open
chibuezemicahe
wants to merge
8
commits into
hngprojects:dev
Choose a base branch
from
chibuezemicahe:feature/billing-plan-pagination
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7b57a24
feat: Implemented pagination to getAllBilling Plans Endpoint
chibuezemicahe bd6b113
docs: added pagination to the getallbilling plan end point doc
chibuezemicahe 119519a
feat: implemented pagination to get all billing plans endpoint
chibuezemicahe 764e688
refactor: femporary commit to switch branches
chibuezemicahe 30fd682
Merge branch 'dev' into feature/billing-plan-pagination
chibuezemicahe 99c0069
Merge branch 'dev' into feature/billing-plan-pagination
chibuezemicahe 3431a4e
Merge branch 'hngprojects:dev' into feature/billing-plan-pagination
chibuezemicahe b968b9e
Merge branch 'dev' into feature/billing-plan-pagination
chibuezemicahe 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -67,7 +67,7 @@ describe('BillingPlanService', () => { | |
}); | ||
|
||
describe('getAllBillingPlans', () => { | ||
it('should return all billing plans', async () => { | ||
it('should return paginated billing plans', async () => { | ||
const billingPlans = [ | ||
{ | ||
id: '1', | ||
|
@@ -105,25 +105,40 @@ describe('BillingPlanService', () => { | |
expirationDate: new Date(), | ||
email: '[email protected]', | ||
}, | ||
]; | ||
|
||
jest.spyOn(repository, 'find').mockResolvedValue(billingPlans as BillingPlan[]); | ||
|
||
const result = await service.getAllBillingPlans(); | ||
|
||
]; | ||
|
||
const total = 2; // Total number of billing plans in the database | ||
|
||
// Mock findAndCount to return paginated results | ||
jest.spyOn(repository, 'findAndCount').mockResolvedValue([billingPlans as BillingPlan[], total]); | ||
|
||
const result = await service.getAllBillingPlans(1, 10); | ||
|
||
// Verify the response structure | ||
expect(result).toEqual({ | ||
message: 'Billing plans retrieved successfully', | ||
data: billingPlans.map(plan => BillingPlanMapper.mapToResponseFormat(plan)), | ||
data: { | ||
plans: billingPlans.map(plan => BillingPlanMapper.mapToResponseFormat(plan)), | ||
total, | ||
}, | ||
}); | ||
|
||
// Verify that findAndCount was called with the correct pagination parameters | ||
expect(repository.findAndCount).toHaveBeenCalledWith({ | ||
skip: 0, // (page - 1) * limit = (1 - 1) * 10 = 0 | ||
take: 10, // limit = 10 | ||
}); | ||
}); | ||
|
||
it('should throw a NotFoundException if no billing plans are found', async () => { | ||
jest.spyOn(repository, 'find').mockResolvedValue([]); | ||
|
||
await expect(service.getAllBillingPlans()).rejects.toThrow(NotFoundException); | ||
// Mock findAndCount to return an empty array | ||
jest.spyOn(repository, 'findAndCount').mockResolvedValue([[], 0]); | ||
|
||
await expect(service.getAllBillingPlans(1, 10)).rejects.toThrow(NotFoundException); | ||
}); | ||
}); | ||
|
||
describe('getSingleBillingPlan', () => { | ||
it('should return a single billing plan', async () => { | ||
const billingPlan = { | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has been deleted