-
Notifications
You must be signed in to change notification settings - Fork 16
Fix: Implement pagination for article file list retrieval in Figshare Service #3526
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
8 commits
Select commit
Hold shift + click to select a range
4f806c7
Fix: Implement pagination for article file list retrieval in Figshare…
andrewbrazzatti 7ccb411
Merge branch 'master' into bugfix/figshare-pagination-issue
andrewbrazzatti 08daeac
Fix: Update entrypoint in docker-compose files to use local nyc binar…
andrewbrazzatti ab33f26
Merge branch 'bugfix/figshare-pagination-issue' of github.com:redbox-…
andrewbrazzatti a6915c8
Fix: Update Docker images in integration testing configurations to us…
andrewbrazzatti 4f2da9e
Fix: Improve pagination logic in FigshareService and update test case…
andrewbrazzatti 7c6b51b
Fix: Add TypeScript ignore comments for dynamic import of chai in Fig…
andrewbrazzatti 224cdc1
Change FigshareService baseURL for testing to include localhost
andrewbrazzatti 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
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
160 changes: 160 additions & 0 deletions
160
typescript/api/test/unit/services/FigshareService.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,160 @@ | ||
| const { describe, it, beforeEach, before } = require('mocha'); | ||
|
|
||
| // Minimal sails stub required by FigshareService | ||
| (global as any).sails = { | ||
| config: { | ||
| figshareAPIEnv: { | ||
| overrideArtifacts: { | ||
| mapping: { | ||
| artifacts: {} | ||
| } | ||
| } | ||
| }, | ||
| figshareAPI: { | ||
| APIToken: 'test-token', | ||
| baseURL: 'https://api.figshare.test.localhost', | ||
| frontEndURL: 'https://figshare.test.localhost', | ||
| mapping: { | ||
| upload: { | ||
| fileListPageSize: 2, | ||
| override: {} | ||
| }, | ||
| figshareOnlyPublishSelectedAttachmentFiles: false, | ||
| recordAllFilesUploaded: false, | ||
| targetState: {}, | ||
| response: { | ||
| article: {} | ||
| } | ||
| }, | ||
| diskSpaceThreshold: 0 | ||
| }, | ||
| figshareReDBoxFORMapping: { | ||
| FORMapping: [] | ||
| }, | ||
| record: { | ||
| createUpdateFigshareArticleLogLevel: 'verbose' | ||
| }, | ||
| queue: { | ||
| serviceName: '' | ||
| } | ||
| }, | ||
| log: { | ||
| verbose: () => {}, | ||
| info: () => {}, | ||
| error: () => {}, | ||
| warn: () => {}, | ||
| debug: () => {} | ||
| }, | ||
| services: {}, | ||
| on: () => {} | ||
| }; | ||
|
|
||
| // axios is required at module load in FigshareService, so we must set the stub before importing it | ||
| const axiosCalls: any[] = []; | ||
| let axiosResponses: any[] = []; | ||
| const axiosStub = (config) => { | ||
| axiosCalls.push(config); | ||
| if (!axiosResponses.length) { | ||
| return Promise.reject(new Error('No axios mock response available')); | ||
| } | ||
| return Promise.resolve(axiosResponses.shift()); | ||
| }; | ||
| (require as any).cache[require.resolve('axios')] = { exports: axiosStub as any }; | ||
|
|
||
| const { Services } = require('../../../services/FigshareService'); | ||
| const FigshareService = Services.FigshareService; | ||
|
|
||
| describe('FigshareService - getArticleFileList pagination', () => { | ||
andrewbrazzatti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let service; | ||
| let expect; | ||
|
|
||
| before(async () => { | ||
| // @ts-ignore | ||
| const chai = await import('chai'); | ||
| expect = chai.expect; | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| axiosCalls.length = 0; | ||
| axiosResponses = []; | ||
| service = new FigshareService(); | ||
| // Set required properties that are private in TS but accessible at runtime | ||
| (service as any).baseURL = 'https://api.figshare.test.localhost'; | ||
| (service as any).APIToken = 'test-token'; | ||
| (global as any).sails.config.figshareAPI.mapping.upload.fileListPageSize = 2; | ||
| }); | ||
|
|
||
| it('aggregates multiple pages until a partial page is returned', async () => { | ||
| axiosResponses = [ | ||
| { status: 200, statusText: 'OK', data: [{ id: 1 }, { id: 2 }] }, | ||
| { status: 200, statusText: 'OK', data: [{ id: 3 }] } | ||
| ]; | ||
|
|
||
| const files = await (service as any).getArticleFileList('123'); | ||
|
|
||
| expect(files.map((f) => f.id)).to.deep.equal([1, 2, 3]); | ||
| expect(axiosCalls).to.have.length(2); | ||
| expect(axiosCalls[0].url).to.contain('/account/articles/123/files?page_size=2&page=1'); | ||
| expect(axiosCalls[1].url).to.contain('/account/articles/123/files?page_size=2&page=2'); | ||
| }); | ||
|
|
||
| it('falls back to the default page size when the config value is invalid', async () => { | ||
| (global as any).sails.config.figshareAPI.mapping.upload.fileListPageSize = 'invalid'; | ||
| const expectedDefault = 20; | ||
|
|
||
| axiosResponses = [ | ||
| { status: 200, statusText: 'OK', data: [{ id: 'a' }] } | ||
| ]; | ||
|
|
||
| const files = await (service as any).getArticleFileList('abc'); | ||
|
|
||
| expect(files.map((f) => f.id)).to.deep.equal(['a']); | ||
| expect(axiosCalls).to.have.length(1); | ||
| expect(axiosCalls[0].url).to.contain(`/account/articles/abc/files?page_size=${expectedDefault}&page=1`); | ||
| }); | ||
|
|
||
| it('returns an empty list when no files are found', async () => { | ||
| axiosResponses = [ | ||
| { status: 200, statusText: 'OK', data: [] } | ||
| ]; | ||
|
|
||
| const files = await (service as any).getArticleFileList('empty'); | ||
|
|
||
| expect(files).to.deep.equal([]); | ||
| expect(axiosCalls).to.have.length(1); | ||
| expect(axiosCalls[0].url).to.contain('/account/articles/empty/files?page_size=2&page=1'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('FigshareService - isFileUploadInProgress', () => { | ||
| let service; | ||
| let expect; | ||
|
|
||
| before(async () => { | ||
| // @ts-ignore | ||
| const chai = await import('chai'); | ||
| expect = chai.expect; | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| service = new FigshareService(); | ||
| (service as any).baseURL = 'https://api.figshare.test.localhost'; | ||
| (service as any).APIToken = 'test-token'; | ||
| }); | ||
|
|
||
| it('returns true when any file has status "created"', async () => { | ||
| const mockFileList = [{ id: 1, status: 'available' }, { id: 2, status: 'created' }]; | ||
|
|
||
| const inProgress = await (service as any).isFileUploadInProgress('article-1', mockFileList); | ||
|
|
||
| expect(inProgress).to.equal(true); | ||
| }); | ||
|
|
||
| it('returns false when no files are in progress', async () => { | ||
| const mockFileList = [{ id: 1, status: 'available' }]; | ||
|
|
||
| const inProgress = await (service as any).isFileUploadInProgress('article-2', mockFileList); | ||
|
|
||
| expect(inProgress).to.equal(false); | ||
| }); | ||
| }); | ||
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.