2017-08-29 15:37:17 +00:00
|
|
|
/* eslint-disable flowtype/require-valid-file-annotation */
|
|
|
|
import TestServer from 'fetch-test-server';
|
|
|
|
import app from '..';
|
|
|
|
import { flushdb, seed } from '../test/support';
|
2018-02-18 09:14:51 +00:00
|
|
|
import { buildUser } from '../test/factories';
|
2018-02-18 18:56:56 +00:00
|
|
|
import { Collection } from '../models';
|
2017-08-29 15:37:17 +00:00
|
|
|
const server = new TestServer(app.callback());
|
|
|
|
|
|
|
|
beforeEach(flushdb);
|
|
|
|
afterAll(server.close);
|
|
|
|
|
|
|
|
describe('#collections.list', async () => {
|
|
|
|
it('should require authentication', async () => {
|
|
|
|
const res = await server.post('/api/collections.list');
|
|
|
|
const body = await res.json();
|
|
|
|
|
|
|
|
expect(res.status).toEqual(401);
|
|
|
|
expect(body).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return collections', async () => {
|
|
|
|
const { user, collection } = await seed();
|
|
|
|
const res = await server.post('/api/collections.list', {
|
|
|
|
body: { token: user.getJwtToken() },
|
|
|
|
});
|
|
|
|
const body = await res.json();
|
|
|
|
|
|
|
|
expect(res.status).toEqual(200);
|
|
|
|
expect(body.data.length).toEqual(1);
|
|
|
|
expect(body.data[0].id).toEqual(collection.id);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#collections.info', async () => {
|
2018-02-18 09:14:51 +00:00
|
|
|
it('should return collection', async () => {
|
|
|
|
const { user, collection } = await seed();
|
|
|
|
const res = await server.post('/api/collections.info', {
|
|
|
|
body: { token: user.getJwtToken(), id: collection.id },
|
|
|
|
});
|
|
|
|
const body = await res.json();
|
|
|
|
|
|
|
|
expect(res.status).toEqual(200);
|
|
|
|
expect(body.data.id).toEqual(collection.id);
|
|
|
|
});
|
|
|
|
|
2017-08-29 15:37:17 +00:00
|
|
|
it('should require authentication', async () => {
|
|
|
|
const res = await server.post('/api/collections.info');
|
|
|
|
const body = await res.json();
|
|
|
|
|
|
|
|
expect(res.status).toEqual(401);
|
|
|
|
expect(body).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2018-02-18 09:14:51 +00:00
|
|
|
it('should require authorization', async () => {
|
|
|
|
const { collection } = await seed();
|
|
|
|
const user = await buildUser();
|
2017-08-29 15:37:17 +00:00
|
|
|
const res = await server.post('/api/collections.info', {
|
|
|
|
body: { token: user.getJwtToken(), id: collection.id },
|
|
|
|
});
|
2018-02-20 07:31:18 +00:00
|
|
|
expect(res.status).toEqual(403);
|
2017-08-29 15:37:17 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#collections.create', async () => {
|
|
|
|
it('should require authentication', async () => {
|
|
|
|
const res = await server.post('/api/collections.create');
|
|
|
|
const body = await res.json();
|
|
|
|
|
|
|
|
expect(res.status).toEqual(401);
|
|
|
|
expect(body).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should create collection', async () => {
|
|
|
|
const { user } = await seed();
|
|
|
|
const res = await server.post('/api/collections.create', {
|
|
|
|
body: { token: user.getJwtToken(), name: 'Test', type: 'atlas' },
|
|
|
|
});
|
|
|
|
const body = await res.json();
|
|
|
|
|
|
|
|
expect(res.status).toEqual(200);
|
|
|
|
expect(body.data.id).toBeTruthy();
|
|
|
|
expect(body.data.name).toBe('Test');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#collections.delete', async () => {
|
|
|
|
it('should require authentication', async () => {
|
|
|
|
const res = await server.post('/api/collections.delete');
|
|
|
|
const body = await res.json();
|
|
|
|
|
|
|
|
expect(res.status).toEqual(401);
|
|
|
|
expect(body).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2018-02-18 09:14:51 +00:00
|
|
|
it('should require authorization', async () => {
|
|
|
|
const { collection } = await seed();
|
|
|
|
const user = await buildUser();
|
|
|
|
const res = await server.post('/api/collections.delete', {
|
|
|
|
body: { token: user.getJwtToken(), id: collection.id },
|
|
|
|
});
|
|
|
|
expect(res.status).toEqual(403);
|
|
|
|
});
|
|
|
|
|
2017-08-29 15:37:17 +00:00
|
|
|
it('should not delete last collection', async () => {
|
|
|
|
const { user, collection } = await seed();
|
|
|
|
const res = await server.post('/api/collections.delete', {
|
|
|
|
body: { token: user.getJwtToken(), id: collection.id },
|
|
|
|
});
|
|
|
|
expect(res.status).toEqual(400);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should delete collection', async () => {
|
|
|
|
const { user, collection } = await seed();
|
|
|
|
await Collection.create({
|
|
|
|
name: 'Blah',
|
|
|
|
urlId: 'blah',
|
|
|
|
teamId: user.teamId,
|
|
|
|
creatorId: user.id,
|
|
|
|
type: 'atlas',
|
|
|
|
});
|
|
|
|
|
|
|
|
const res = await server.post('/api/collections.delete', {
|
|
|
|
body: { token: user.getJwtToken(), id: collection.id },
|
|
|
|
});
|
|
|
|
const body = await res.json();
|
|
|
|
|
|
|
|
expect(res.status).toEqual(200);
|
|
|
|
expect(body.success).toBe(true);
|
|
|
|
});
|
|
|
|
});
|