paradigm-core
Version:
Paradigm Core Modules
170 lines (126 loc) • 3.8 kB
JavaScript
const {
Migrations,
TestHelpers: {MockHTTPServer},
} = require('structure-core')
const migrationItems = require('../../../migrations/templates')
const pluginsList = require('../../helpers/plugins')
const server = new MockHTTPServer(pluginsList)
const items = {
tables: migrationItems.tables.concat([
{
action: 'create',
table: 'link_organizations_document_revisions'
},
{
action: 'create',
table: 'link_organizations_template_revisions'
},
{
action: 'create',
table: 'link_users_document_revisions'
},
{
action: 'create',
table: 'link_users_template_revisions'
},
])
}
describe.skip('Templates', function() {
beforeEach(function() {
this.migration = new Migrations({
db: 'test',
items
})
return this.migration.process()
})
afterEach(function() {
return this.migration.purge()
})
it('should create a template', async function() {
var pkg = {
title: 'My Template'
}
var res = await new MockHTTPServer()
.post(`/api/${process.env.API_VERSION}/templates`)
.send(pkg)
expect(res.body.pkg.title).to.equal('My Template')
expect(res.body.status).to.equal(201)
})
it('should get a template by Id', async function() {
const orgRes = await server
.post(`/api/${process.env.API_VERSION}/organizations`)
.send({
title: 'Horcruxes Limited'
})
const org = orgRes.body.pkg
const userRes = await server
.post(`/api/${process.env.API_VERSION}/users`)
.send({
organizationId: org.id,
username: 'tom',
email: 'voldemort@horcruxes.r.us',
password: 'c4ntf1ndmyc4v3br0'
})
const user = userRes.body.pkg
var pkg = {
title: 'My Template',
organizationId: org.id,
userId: user.id
}
var tem = await new MockHTTPServer()
.post(`/api/${process.env.API_VERSION}/templates`)
.send(pkg)
var temId = tem.body.pkg.id
var res = await new MockHTTPServer()
.get(`/api/${process.env.API_VERSION}/templates/${temId}`)
expect(res.body.pkg.title).to.equal('My Template')
expect(res.body.status).to.equal(200)
})
it('should get all templates', async function() {
var pkg = {
title: 'My Template'
}
var tem = await new MockHTTPServer()
.post(`/api/${process.env.API_VERSION}/templates`)
.send(pkg)
var res = await new MockHTTPServer()
.get(`/api/${process.env.API_VERSION}/templates`)
expect(res.body.pkg.templates.length).to.be.above(0)
expect(res.body.status).to.equal(200)
})
it('should update a template by Id', async function() {
const orgRes = await server
.post(`/api/${process.env.API_VERSION}/organizations`)
.send({
title: 'Horcruxes Limited'
})
const org = orgRes.body.pkg
const userRes = await server
.post(`/api/${process.env.API_VERSION}/users`)
.send({
organizationId: org.id,
username: 'tom2',
email: 'voldemort2@horcruxes.r.us',
password: 'c4ntf1ndmyc4v3br0'
})
const user = userRes.body.pkg
var pkg = {
title: 'Template 45',
organizationId: org.id,
userId: user.id
}
var tem = await new MockHTTPServer()
.post(`/api/${process.env.API_VERSION}/templates`)
.send(pkg)
var temId = tem.body.pkg.id
var res = await new MockHTTPServer()
.patch(`/api/${process.env.API_VERSION}/templates/${temId}`)
.send({
title: 'Template 46'
})
var res2 = await new MockHTTPServer()
.get(`/api/${process.env.API_VERSION}/templates/${temId}`)
expect(res2.body.pkg.title).to.equal('Template 46')
expect(res.body.status).to.equal(200)
})
})