Updating application tests to run a lot deeper, which required updating some other tests to account for creation of empty screens and layouts.
This commit is contained in:
parent
a48f1c72f2
commit
a6bde49ad3
|
@ -104,9 +104,10 @@ async function createInstance(template) {
|
||||||
await createRoutingView(appId)
|
await createRoutingView(appId)
|
||||||
|
|
||||||
// replicate the template data to the instance DB
|
// replicate the template data to the instance DB
|
||||||
|
// this is currently very hard to test, downloading and importing template files
|
||||||
|
/* istanbul ignore next */
|
||||||
if (template) {
|
if (template) {
|
||||||
let dbDumpReadStream
|
let dbDumpReadStream
|
||||||
|
|
||||||
if (template.fileImportPath) {
|
if (template.fileImportPath) {
|
||||||
dbDumpReadStream = fs.createReadStream(template.fileImportPath)
|
dbDumpReadStream = fs.createReadStream(template.fileImportPath)
|
||||||
} else {
|
} else {
|
||||||
|
@ -181,8 +182,9 @@ exports.create = async function(ctx) {
|
||||||
const instanceDb = new CouchDB(appId)
|
const instanceDb = new CouchDB(appId)
|
||||||
await instanceDb.put(newApplication)
|
await instanceDb.put(newApplication)
|
||||||
|
|
||||||
if (env.NODE_ENV !== "jest") {
|
|
||||||
const newAppFolder = await createEmptyAppPackage(ctx, newApplication)
|
const newAppFolder = await createEmptyAppPackage(ctx, newApplication)
|
||||||
|
/* istanbul ignore next */
|
||||||
|
if (env.NODE_ENV !== "jest") {
|
||||||
await downloadExtractComponentLibraries(newAppFolder)
|
await downloadExtractComponentLibraries(newAppFolder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,4 +58,43 @@ describe("/applications", () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("fetchAppDefinition", () => {
|
||||||
|
it("should be able to get an apps definition", async () => {
|
||||||
|
const res = await request
|
||||||
|
.get(`/api/applications/${config.getAppId()}/definition`)
|
||||||
|
.set(config.defaultHeaders())
|
||||||
|
.expect('Content-Type', /json/)
|
||||||
|
.expect(200)
|
||||||
|
// should have empty packages
|
||||||
|
expect(res.body.screens.length).toEqual(2)
|
||||||
|
expect(res.body.layouts.length).toEqual(2)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("fetchAppPackage", () => {
|
||||||
|
it("should be able to fetch the app package", async () => {
|
||||||
|
const res = await request
|
||||||
|
.get(`/api/applications/${config.getAppId()}/appPackage`)
|
||||||
|
.set(config.defaultHeaders())
|
||||||
|
.expect('Content-Type', /json/)
|
||||||
|
.expect(200)
|
||||||
|
expect(res.body.application).toBeDefined()
|
||||||
|
expect(res.body.screens.length).toEqual(2)
|
||||||
|
expect(res.body.layouts.length).toEqual(2)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("update", () => {
|
||||||
|
it("should be able to fetch the app package", async () => {
|
||||||
|
const res = await request
|
||||||
|
.put(`/api/applications/${config.getAppId()}`)
|
||||||
|
.send({
|
||||||
|
name: "TEST_APP"
|
||||||
|
})
|
||||||
|
.set(config.defaultHeaders())
|
||||||
|
.expect('Content-Type', /json/)
|
||||||
|
.expect(200)
|
||||||
|
expect(res.body.rev).toBeDefined()
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -73,7 +73,7 @@ describe("/automations", () => {
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
expect(Object.keys(res.body.action).length).toEqual(Object.keys(ACTION_DEFINITIONS).length)
|
expect(Object.keys(res.body.action).length).toBeGreaterThanOrEqual(Object.keys(ACTION_DEFINITIONS).length)
|
||||||
expect(Object.keys(res.body.trigger).length).toEqual(Object.keys(TRIGGER_DEFINITIONS).length)
|
expect(Object.keys(res.body.trigger).length).toEqual(Object.keys(TRIGGER_DEFINITIONS).length)
|
||||||
expect(Object.keys(res.body.logic).length).toEqual(Object.keys(LOGIC_DEFINITIONS).length)
|
expect(Object.keys(res.body.logic).length).toEqual(Object.keys(LOGIC_DEFINITIONS).length)
|
||||||
})
|
})
|
||||||
|
|
|
@ -3,6 +3,8 @@ const { basicScreen } = require("./utilities/structures")
|
||||||
const { checkBuilderEndpoint } = require("./utilities/TestFunctions")
|
const { checkBuilderEndpoint } = require("./utilities/TestFunctions")
|
||||||
const { BUILTIN_ROLE_IDS } = require("../../../utilities/security/roles")
|
const { BUILTIN_ROLE_IDS } = require("../../../utilities/security/roles")
|
||||||
|
|
||||||
|
const route = "/test"
|
||||||
|
|
||||||
describe("/routing", () => {
|
describe("/routing", () => {
|
||||||
let request = setup.getRequest()
|
let request = setup.getRequest()
|
||||||
let config = setup.getConfig()
|
let config = setup.getConfig()
|
||||||
|
@ -12,9 +14,12 @@ describe("/routing", () => {
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await config.init()
|
await config.init()
|
||||||
screen = await config.createScreen(basicScreen())
|
screen = basicScreen()
|
||||||
|
screen.routing.route = route
|
||||||
|
screen = await config.createScreen(screen)
|
||||||
screen2 = basicScreen()
|
screen2 = basicScreen()
|
||||||
screen2.routing.roleId = BUILTIN_ROLE_IDS.POWER
|
screen2.routing.roleId = BUILTIN_ROLE_IDS.POWER
|
||||||
|
screen2.routing.route = route
|
||||||
screen2 = await config.createScreen(screen2)
|
screen2 = await config.createScreen(screen2)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -26,9 +31,9 @@ describe("/routing", () => {
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
expect(res.body.routes).toBeDefined()
|
expect(res.body.routes).toBeDefined()
|
||||||
expect(res.body.routes["/"]).toEqual({
|
expect(res.body.routes[route]).toEqual({
|
||||||
subpaths: {
|
subpaths: {
|
||||||
["/"]: {
|
[route]: {
|
||||||
screenId: screen._id,
|
screenId: screen._id,
|
||||||
roleId: screen.routing.roleId
|
roleId: screen.routing.roleId
|
||||||
}
|
}
|
||||||
|
@ -43,9 +48,9 @@ describe("/routing", () => {
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
expect(res.body.routes).toBeDefined()
|
expect(res.body.routes).toBeDefined()
|
||||||
expect(res.body.routes["/"]).toEqual({
|
expect(res.body.routes[route]).toEqual({
|
||||||
subpaths: {
|
subpaths: {
|
||||||
["/"]: {
|
[route]: {
|
||||||
screenId: screen2._id,
|
screenId: screen2._id,
|
||||||
roleId: screen2.routing.roleId
|
roleId: screen2.routing.roleId
|
||||||
}
|
}
|
||||||
|
@ -62,16 +67,10 @@ describe("/routing", () => {
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
expect(res.body.routes).toBeDefined()
|
expect(res.body.routes).toBeDefined()
|
||||||
expect(res.body.routes["/"]).toEqual({
|
expect(res.body.routes[route].subpaths[route]).toBeDefined()
|
||||||
subpaths: {
|
const subpath = res.body.routes[route].subpaths[route]
|
||||||
["/"]: {
|
expect(subpath.screens[screen2.routing.roleId]).toEqual(screen2._id)
|
||||||
screens: {
|
expect(subpath.screens[screen.routing.roleId]).toEqual(screen._id)
|
||||||
[screen2.routing.roleId]: screen2._id,
|
|
||||||
[screen.routing.roleId]: screen._id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("make sure it is a builder only endpoint", async () => {
|
it("make sure it is a builder only endpoint", async () => {
|
||||||
|
|
|
@ -21,8 +21,8 @@ describe("/screens", () => {
|
||||||
.set(config.defaultHeaders())
|
.set(config.defaultHeaders())
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
expect(res.body.length).toEqual(1)
|
expect(res.body.length).toEqual(3)
|
||||||
expect(res.body[0]._id).toEqual(screen._id)
|
expect(res.body.some(s => s._id === screen._id)).toEqual(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should apply authorization to endpoint", async () => {
|
it("should apply authorization to endpoint", async () => {
|
||||||
|
|
|
@ -241,7 +241,7 @@ class TestConfiguration {
|
||||||
async createUser(
|
async createUser(
|
||||||
email = EMAIL,
|
email = EMAIL,
|
||||||
password = PASSWORD,
|
password = PASSWORD,
|
||||||
roleId = BUILTIN_ROLE_IDS.POWER,
|
roleId = BUILTIN_ROLE_IDS.POWER
|
||||||
) {
|
) {
|
||||||
return this._req(
|
return this._req(
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue