-
Notifications
You must be signed in to change notification settings - Fork 730
feat: implment bulk radius api (CM-1328) #4390
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
+1,637
−150
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8976d30
feat: implment bulk radius api
ulemons 6d0d870
feat: add tests
ulemons 72f305d
fix: test
ulemons 7aaecba
fix: max concurrency for pg
ulemons 33d880c
fix: modify hearthbit test 20 adv
ulemons 0ed4591
feat: optimize bulk calls
ulemons d24e6ff
feat: revert authentication and rate limit
ulemons 1839ac5
fix: lint
ulemons ba7b467
fix: comments
ulemons 970c41c
fix: comments
ulemons 6959163
fix: rate limit to 5 per hour
ulemons 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
93 changes: 93 additions & 0 deletions
93
backend/src/api/public/v1/packages/blastRadiusBatch.test.ts
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,93 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| import { | ||
| MAX_BLAST_RADIUS_JOBS_PER_BATCH, | ||
| MAX_BLAST_RADIUS_POLL_IDS_PER_BATCH, | ||
| blastRadiusJobBatchRequestSchema, | ||
| blastRadiusJobPollBatchRequestSchema, | ||
| paginateAnalysisIds, | ||
| } from './blastRadiusBatch' | ||
|
|
||
| describe('blastRadiusJobBatchRequestSchema', () => { | ||
| it('accepts a batch of valid job requests', () => { | ||
| const result = blastRadiusJobBatchRequestSchema.safeParse({ | ||
| jobs: [ | ||
| { advisoryId: 'GHSA-jf85-cpcp-j695', ecosystem: 'npm' }, | ||
| { advisoryId: 'CVE-2024-12345', ecosystem: 'npm', package: 'pkg:npm/lodash' }, | ||
| ], | ||
| }) | ||
| expect(result.success).toBe(true) | ||
| }) | ||
|
|
||
| it('rejects an empty jobs array', () => { | ||
| const result = blastRadiusJobBatchRequestSchema.safeParse({ jobs: [] }) | ||
| expect(result.success).toBe(false) | ||
| }) | ||
|
|
||
| it('rejects more than MAX_BLAST_RADIUS_JOBS_PER_BATCH jobs', () => { | ||
| const jobs = Array.from({ length: MAX_BLAST_RADIUS_JOBS_PER_BATCH + 1 }, () => ({ | ||
| advisoryId: 'GHSA-jf85-cpcp-j695', | ||
| ecosystem: 'npm', | ||
| })) | ||
| const result = blastRadiusJobBatchRequestSchema.safeParse({ jobs }) | ||
| expect(result.success).toBe(false) | ||
| }) | ||
|
|
||
| it('rejects a batch containing one invalid job', () => { | ||
| const result = blastRadiusJobBatchRequestSchema.safeParse({ | ||
| jobs: [ | ||
| { advisoryId: 'GHSA-jf85-cpcp-j695', ecosystem: 'npm' }, | ||
| { advisoryId: 'not-an-advisory-id', ecosystem: 'npm' }, | ||
| ], | ||
| }) | ||
| expect(result.success).toBe(false) | ||
| }) | ||
| }) | ||
|
|
||
| describe('blastRadiusJobPollBatchRequestSchema', () => { | ||
| const validId = '3fa85f64-5717-4562-b3fc-2c963f66afa6' | ||
|
|
||
| it('accepts a batch of valid analysisIds and defaults page/pageSize', () => { | ||
| const result = blastRadiusJobPollBatchRequestSchema.parse({ analysisIds: [validId] }) | ||
| expect(result.page).toBe(1) | ||
| expect(result.pageSize).toBe(20) | ||
| }) | ||
|
|
||
| it('rejects an empty analysisIds array', () => { | ||
| const result = blastRadiusJobPollBatchRequestSchema.safeParse({ analysisIds: [] }) | ||
| expect(result.success).toBe(false) | ||
| }) | ||
|
|
||
| it('rejects a non-uuid analysisId', () => { | ||
| const result = blastRadiusJobPollBatchRequestSchema.safeParse({ analysisIds: ['not-a-uuid'] }) | ||
| expect(result.success).toBe(false) | ||
| }) | ||
|
|
||
| it('rejects more than MAX_BLAST_RADIUS_POLL_IDS_PER_BATCH analysisIds', () => { | ||
| const analysisIds = Array.from( | ||
| { length: MAX_BLAST_RADIUS_POLL_IDS_PER_BATCH + 1 }, | ||
| () => validId, | ||
| ) | ||
| const result = blastRadiusJobPollBatchRequestSchema.safeParse({ analysisIds }) | ||
| expect(result.success).toBe(false) | ||
| }) | ||
| }) | ||
|
|
||
| describe('paginateAnalysisIds', () => { | ||
| it('slices the requested page out of the full analysisIds array', () => { | ||
| const analysisIds = ['a', 'b', 'c', 'd', 'e'] | ||
| const result = paginateAnalysisIds({ analysisIds, page: 2, pageSize: 2 }) | ||
| expect(result).toEqual({ | ||
| page: 2, | ||
| pageSize: 2, | ||
| total: 5, | ||
| pagedAnalysisIds: ['c', 'd'], | ||
| }) | ||
| }) | ||
|
|
||
| it('returns an empty page past the end of the array', () => { | ||
| const result = paginateAnalysisIds({ analysisIds: ['a'], page: 2, pageSize: 20 }) | ||
| expect(result.pagedAnalysisIds).toEqual([]) | ||
| expect(result.total).toBe(1) | ||
| }) | ||
| }) |
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.