-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new handlers to get workbooks and collections list by ids (#210)
* Add new handler getWorkbooksListByIds * Add route getCollectionsListByIds * Add int tests * Change test * Refactor * Refactor getCollectionsListByIds service * Add additional tests * Change route name * Add features
- Loading branch information
1 parent
fed7145
commit 030b6aa
Showing
9 changed files
with
339 additions
and
25 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
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
104 changes: 104 additions & 0 deletions
104
src/tests/int/env/platform/suites/collections/get-collections-list-by-ids.test.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,104 @@ | ||
import request from 'supertest'; | ||
import {app, auth, getCollectionBinding, US_ERRORS} from '../../auth'; | ||
import {createMockCollection} from '../../helpers'; | ||
import {routes} from '../../../../routes'; | ||
import {COLLECTIONS_DEFAULT_FIELDS} from '../../../../models'; | ||
|
||
const rootCollection = { | ||
collectionId: '', | ||
title: 'Empty root collection', | ||
}; | ||
|
||
const rootCollection2 = { | ||
collectionId: '', | ||
title: 'Empty root collection 2', | ||
}; | ||
|
||
describe('Setup', () => { | ||
test('Create collections', async () => { | ||
const collection = await createMockCollection({ | ||
title: rootCollection.title, | ||
parentId: null, | ||
}); | ||
rootCollection.collectionId = collection.collectionId; | ||
|
||
const collection2 = await createMockCollection({ | ||
title: rootCollection2.title, | ||
parentId: null, | ||
}); | ||
rootCollection2.collectionId = collection2.collectionId; | ||
}); | ||
}); | ||
|
||
describe('Get collections by ids', () => { | ||
test('Auth error', async () => { | ||
await request(app) | ||
.post(routes.getCollectionsListByIds) | ||
.send({ | ||
collectionIds: [rootCollection.collectionId, rootCollection2.collectionId], | ||
}) | ||
.expect(401); | ||
}); | ||
|
||
test('Get list without permissions, should return empty list', async () => { | ||
const response = await auth(request(app).post(routes.getCollectionsListByIds)) | ||
.send({ | ||
collectionIds: [rootCollection.collectionId, rootCollection2.collectionId], | ||
}) | ||
.expect(200); | ||
|
||
expect(response.body).toStrictEqual([]); | ||
}); | ||
|
||
test('Get list with permission only 1 collection, should return 1 collection', async () => { | ||
const response = await auth(request(app).post(routes.getCollectionsListByIds), { | ||
accessBindings: [getCollectionBinding(rootCollection.collectionId, 'limitedView')], | ||
}) | ||
.send({ | ||
collectionIds: [rootCollection.collectionId, rootCollection.collectionId], | ||
}) | ||
.expect(200); | ||
|
||
expect(response.body).toStrictEqual([ | ||
{ | ||
...COLLECTIONS_DEFAULT_FIELDS, | ||
collectionId: rootCollection.collectionId, | ||
}, | ||
]); | ||
}); | ||
|
||
test('Get list without ids, should be a validation error', async () => { | ||
const response = await auth(request(app).post(routes.getCollectionsListByIds), { | ||
accessBindings: [ | ||
getCollectionBinding(rootCollection.collectionId, 'limitedView'), | ||
getCollectionBinding(rootCollection2.collectionId, 'limitedView'), | ||
], | ||
}).expect(400); | ||
|
||
expect(response.body.code).toBe(US_ERRORS.VALIDATION_ERROR); | ||
}); | ||
|
||
test('Successfully get list by ids', async () => { | ||
const response = await auth(request(app).post(routes.getCollectionsListByIds), { | ||
accessBindings: [ | ||
getCollectionBinding(rootCollection.collectionId, 'limitedView'), | ||
getCollectionBinding(rootCollection2.collectionId, 'limitedView'), | ||
], | ||
}) | ||
.send({ | ||
collectionIds: [rootCollection.collectionId, rootCollection2.collectionId], | ||
}) | ||
.expect(200); | ||
|
||
expect(response.body).toStrictEqual([ | ||
{ | ||
...COLLECTIONS_DEFAULT_FIELDS, | ||
collectionId: rootCollection.collectionId, | ||
}, | ||
{ | ||
...COLLECTIONS_DEFAULT_FIELDS, | ||
collectionId: rootCollection2.collectionId, | ||
}, | ||
]); | ||
}); | ||
}); |
Oops, something went wrong.