paradigm-core
Version:
Paradigm Core Modules
182 lines (129 loc) • 4.17 kB
JavaScript
const {
Migrations,
TestHelpers: {MockHTTPServer},
} = require('structure-core')
const pluginsList = require('../helpers/plugins')
const server = new MockHTTPServer(pluginsList)
const createOrgAndApp = async function() {
// getting an organization and application Ids
var res0 = await server
.post(`/api/${process.env.API_VERSION}/organizations`)
.send({
title: 'work it'
})
const org = res0.body.pkg
const orgId = org.id
var app = await server
.post(`/api/${process.env.API_VERSION}/applications`)
.set('organizationid', orgId)
.send({
desc: '',
title: 'App 45'
})
const appId = app.body.pkg.id
return {orgId, appId}
}
describe('Themes Routes', function() {
beforeEach(function() {
this.migration = new Migrations({
db: 'test',
plugins: pluginsList
})
return this.migration.process()
})
afterEach(function() {
return this.migration.purge()
})
it('should create a theme', async function() {
const {orgId, appId} = await createOrgAndApp()
var pkg = {}
var res = await server
.post(`/api/${process.env.API_VERSION}/themes`)
.set('organizationid', orgId)
.set('applicationid', appId)
.send(pkg)
expect(res.body.status).to.equal(201)
})
it('should get a theme by Id', async function() {
const {orgId, appId} = await createOrgAndApp()
var pkg = {}
var theme = await server
.post(`/api/${process.env.API_VERSION}/themes`)
.set('organizationid', orgId)
.set('applicationid', appId)
.send(pkg)
const themeId = theme.body.pkg.id
var res = await server
.get(`/api/${process.env.API_VERSION}/themes/${themeId}`)
.set('organizationid', orgId)
.set('applicationid', appId)
expect(res.body.status).to.equal(200)
})
it('should get all themes', async function() {
const {orgId, appId} = await createOrgAndApp()
var pkg = {}
var app = await server
.post(`/api/${process.env.API_VERSION}/themes`)
.set('organizationid', orgId)
.set('applicationid', appId)
.send(pkg)
var res = await server
.get(`/api/${process.env.API_VERSION}/themes`)
.set('organizationid', orgId)
.set('applicationid', appId)
expect(res.body.pkg.themes.length).to.be.above(0)
expect(res.body.status).to.equal(200)
})
it('should get all themes from correct organization', async function() {
const res0 = await createOrgAndApp()
const org1Id = res0.orgId
const app1Id = res0.appId
const res1 = await createOrgAndApp()
const org2Id = res1.orgId
const app2Id = res1.appId
await server
.post(`/api/${process.env.API_VERSION}/themes`)
.set('organizationid', org1Id)
.set('applicationid', app1Id)
.send({
foo: 'bar'
})
await server
.post(`/api/${process.env.API_VERSION}/themes`)
.set('organizationid', org2Id)
.set('applicationid', app2Id)
.send({
foo: 'baz'
})
var res = await server
.get(`/api/${process.env.API_VERSION}/themes`)
.set('organizationid', org2Id)
.set('applicationid', app2Id)
expect(res.body.status).to.equal(200)
expect(res.body.pkg.themes.length).to.equal(1)
expect(res.body.pkg.themes[0].foo).to.equal('baz')
})
it('should update a theme by Id', async function() {
const {orgId, appId} = await createOrgAndApp()
var pkg = {}
var theme = await server
.post(`/api/${process.env.API_VERSION}/themes`)
.set('organizationid', orgId)
.set('applicationid', appId)
.send(pkg)
const themeId = theme.body.pkg.id
var res = await server
.patch(`/api/${process.env.API_VERSION}/themes/${themeId}`)
.set('organizationid', orgId)
.set('applicationid', appId)
.send({
title: 'peekaboo'
})
var res2 = await server
.get(`/api/${process.env.API_VERSION}/themes/${themeId}`)
.set('organizationid', orgId)
.set('applicationid', appId)
expect(res2.body.pkg.title).to.equal('peekaboo')
expect(res.body.status).to.equal(200)
})
})