UNPKG

structure-event-collector

Version:
123 lines (84 loc) 2.64 kB
import EventController from '../../src/controllers/event' import EventModel from '../../src/models/event' import migrationItems from '../../src/migrations' import Migrations from 'structure-migrations' import MockHTTPServer from '../helpers/mock-http-server' import r from 'structure-driver' Migrations.prototype.r = r describe('Routes', function() { beforeEach(function() { this.migration = new Migrations({ db: 'test', items: migrationItems }) return this.migration.process() }) afterEach(function() { return this.migration.purge() }) it('should create an event', async function() { var event = new EventController() var pkg = { label: 'foo', data: { desc: '', title: 'App 45' } } var res = await new MockHTTPServer() .post(`/api/${process.env.API_VERSION}/events`) .send(pkg) expect(res.body.pkg.data.title).to.equal('App 45') expect(res.body.status).to.equal(201) }) it('should get an event by Id', async function() { var event = new EventController() var pkg = { desc: '', title: 'App 45' } var app = await new MockHTTPServer() .post(`/api/${process.env.API_VERSION}/events`) .send(pkg) var appId = app.body.pkg.id var res = await new MockHTTPServer() .get(`/api/${process.env.API_VERSION}/events/${appId}`) expect(res.body.pkg.title).to.equal('App 45') expect(res.body.status).to.equal(200) }) it('should get all events', async function() { var event = new EventController() var pkg = { desc: '', title: 'App 45' } var app = await new MockHTTPServer() .post(`/api/${process.env.API_VERSION}/events`) .send(pkg) var res = await new MockHTTPServer() .get(`/api/${process.env.API_VERSION}/events`) expect(res.body.pkg.events.length).to.be.above(0) expect(res.body.status).to.equal(200) }) it('should update an event by Id', async function() { var event = new EventController() var pkg = { desc: '', title: 'App 45' } var app = await new MockHTTPServer() .post(`/api/${process.env.API_VERSION}/events`) .send(pkg) var appId = app.body.pkg.id var res = await new MockHTTPServer() .patch(`/api/${process.env.API_VERSION}/events/${appId}`) .send({ desc: '', title: 'App 46' }) var res2 = await new MockHTTPServer() .get(`/api/${process.env.API_VERSION}/events/${appId}`) expect(res2.body.pkg.title).to.equal('App 46') expect(res.body.status).to.equal(200) }) })