UNPKG

paradigm-core

Version:
229 lines (170 loc) 5.63 kB
const { Migrations, OrganizationsPlugin, ApplicationsPlugin, TestHelpers: {MockHTTPServer}, } = require('structure-core') const pluginsList = require('../helpers/plugins') const server = new MockHTTPServer(pluginsList) const orgTestApi = new OrganizationsPlugin.TestAPI(server) const appTestApi = new ApplicationsPlugin.TestAPI(server) describe('Taxonomies Routes', function() { before(function() { this.migration = new Migrations({ db: 'test', plugins: pluginsList }) return this.migration.process() }) beforeEach(async function() { const orgRes = await orgTestApi.create({ title: 'Test Org' }) this.orgId = orgRes.body.pkg.id const appRes = await appTestApi.create(this.orgId, { title: 'Test App', }) this.appId = appRes.body.pkg.id }) afterEach(function() { return this.migration.purge() }) it('should create an taxonomy', async function() { var pkg = { desc: '', title: 'lol' } var res = await server .post(`/api/${process.env.API_VERSION}/taxonomies`) .set('organizationid', this.orgId) .set('applicationid', this.appId) .send(pkg) expect(res.body.pkg.title).to.equal('lol') expect(res.body.status).to.equal(201) }) it('should get an taxonomy by Id', async function() { var pkg = { desc: '', title: 'rofl' } var taxonomy = await server .post(`/api/${process.env.API_VERSION}/taxonomies`) .set('organizationid', this.orgId) .set('applicationid', this.appId) .send(pkg) var taxonomyId = taxonomy.body.pkg.id var res = await server .get(`/api/${process.env.API_VERSION}/taxonomies/${taxonomyId}`) .set('organizationid', this.orgId) .set('applicationid', this.appId) expect(res.body.pkg.title).to.equal('rofl') expect(res.body.status).to.equal(200) }) it('should get an taxonomy by slug', async function() { var res0 = await server .post(`/api/${process.env.API_VERSION}/taxonomies`) .set('organizationid', this.orgId) .set('applicationid', this.appId) .send({ desc: '', title: 'rofl' }) var tag = res0.body.pkg var res = await server .get(`/api/${process.env.API_VERSION}/taxonomies/slug/${tag.slug}`) .set('organizationid', this.orgId) .set('applicationid', this.appId) expect(res.body.pkg.title).to.equal('rofl') expect(res.body.status).to.equal(200) }) it('should match a taxonomy by slug', async function() { var res0 = await server .post(`/api/${process.env.API_VERSION}/taxonomies`) .set('organizationid', this.orgId) .set('applicationid', this.appId) .send({ desc: '', title: 'rofl' }) var tag = res0.body.pkg var res = await server .get(`/api/${process.env.API_VERSION}/taxonomies/match/${tag.slug}`) .set('organizationid', this.orgId) .set('applicationid', this.appId) const taxonomies = res.body.pkg expect(taxonomies[0].title).to.equal('rofl') expect(res.body.status).to.equal(200) }) it('should get all taxonomies', async function() { var pkg = { desc: '', title: 'lulz' } await server .post(`/api/${process.env.API_VERSION}/taxonomies`) .set('organizationid', this.orgId) .set('applicationid', this.appId) .send(pkg) var res = await server .get(`/api/${process.env.API_VERSION}/taxonomies`) .set('organizationid', this.orgId) .set('applicationid', this.appId) expect(res.body.pkg.pagination.pages).to.equal(1) expect(res.body.pkg.pagination.current).to.equal(1) expect(res.body.pkg.pagination.total).to.equal(1) expect(res.body.pkg.pagination.next).to.be.false expect(res.body.pkg.pagination.previous).to.be.false expect(res.body.pkg.taxonomies.length).to.equal(1) expect(res.body.status).to.equal(200) }) it('should create taxonomy once', async function() { await server .post(`/api/${process.env.API_VERSION}/taxonomies`) .set('organizationid', this.orgId) .set('applicationid', this.appId) .send({ desc: '', title: 'lulz' }) await server .post(`/api/${process.env.API_VERSION}/taxonomies`) .set('organizationid', this.orgId) .set('applicationid', this.appId) .send({ desc: '', title: 'lulz' }) var res = await server .get(`/api/${process.env.API_VERSION}/taxonomies`) .set('organizationid', this.orgId) .set('applicationid', this.appId) expect(res.body.pkg.taxonomies.length).to.equal(1) expect(res.body.status).to.equal(200) }) it('should update an taxonomy by Id', async function() { var pkg = { desc: '', title: 'peeka' } var taxonomy = await server .post(`/api/${process.env.API_VERSION}/taxonomies`) .set('organizationid', this.orgId) .set('applicationid', this.appId) .send(pkg) var taxonomyId = taxonomy.body.pkg.id var res = await server .patch(`/api/${process.env.API_VERSION}/taxonomies/${taxonomyId}`) .set('organizationid', this.orgId) .set('applicationid', this.appId) .send({ desc: '', title: 'peekaboo' }) var res2 = await server .get(`/api/${process.env.API_VERSION}/taxonomies/${taxonomyId}`) .set('organizationid', this.orgId) .set('applicationid', this.appId) expect(res2.body.pkg.title).to.equal('peekaboo') expect(res.body.status).to.equal(200) }) })