Filter shares.list endpoint by admin

This commit is contained in:
Tom Moor
2018-05-23 22:55:01 -07:00
parent 47fb968009
commit aeb97ddcae
2 changed files with 30 additions and 3 deletions

View File

@ -10,12 +10,17 @@ beforeEach(flushdb);
afterAll(server.close);
describe('#shares.list', async () => {
it('should return a list of shares', async () => {
it('should only return shares created by user', async () => {
const { user, document } = await seed();
const share = await buildShare({
await buildShare({
documentId: document.id,
teamId: user.teamId,
});
const share = await buildShare({
documentId: document.id,
teamId: user.teamId,
userId: user.id,
});
const res = await server.post('/api/shares.list', {
body: { token: user.getJwtToken() },
});
@ -27,6 +32,23 @@ describe('#shares.list', async () => {
expect(body.data[0].documentTitle).toBe(document.title);
});
it('admins should only return shares created by all users', async () => {
const { admin, document } = await seed();
const share = await buildShare({
documentId: document.id,
teamId: admin.teamId,
});
const res = await server.post('/api/shares.list', {
body: { token: admin.getJwtToken() },
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.length).toEqual(1);
expect(body.data[0].id).toEqual(share.id);
expect(body.data[0].documentTitle).toBe(document.title);
});
it('should require authentication', async () => {
const res = await server.post('/api/shares.list');
const body = await res.json();