tests
This commit is contained in:
parent
1bb06ccdef
commit
9c3c38d0ac
|
@ -44,8 +44,9 @@ export const prepareRenderComponent = ({
|
||||||
const unsubscribe = appStore.subscribe(state => {
|
const unsubscribe = appStore.subscribe(state => {
|
||||||
const storeBoundProps = { ...initialProps._bb.props }
|
const storeBoundProps = { ...initialProps._bb.props }
|
||||||
for (let prop in storeBoundProps) {
|
for (let prop in storeBoundProps) {
|
||||||
if (typeof storeBoundProps[prop] === "string") {
|
const propValue = storeBoundProps[prop]
|
||||||
storeBoundProps[prop] = mustache.render(storeBoundProps[prop], {
|
if (typeof propValue === "string") {
|
||||||
|
storeBoundProps[prop] = mustache.render(propValue, {
|
||||||
state,
|
state,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,3 @@ export const setState = (path, value) => {
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// export const setStateFromBinding = (store, binding, value) => {
|
|
||||||
// const parsedBinding = parseBinding(binding)
|
|
||||||
// if (!parsedBinding) return
|
|
||||||
// return setState(store, parsedBinding.path, value)
|
|
||||||
// }
|
|
||||||
|
|
|
@ -65,6 +65,7 @@ const _setup = ({ handlerTypes, getCurrentState, bb, store }) => node => {
|
||||||
const isBound = typeof propValue === "string" && propValue.startsWith("{{")
|
const isBound = typeof propValue === "string" && propValue.startsWith("{{")
|
||||||
|
|
||||||
if (isBound) {
|
if (isBound) {
|
||||||
|
console.log("NODE IS BOUND", node);
|
||||||
initialProps[propName] = mustache.render(propValue, {
|
initialProps[propName] = mustache.render(propValue, {
|
||||||
state: currentStoreState,
|
state: currentStoreState,
|
||||||
context,
|
context,
|
||||||
|
|
|
@ -5,13 +5,7 @@ const {
|
||||||
createModel,
|
createModel,
|
||||||
supertest,
|
supertest,
|
||||||
defaultHeaders,
|
defaultHeaders,
|
||||||
testPermissionsForEndpoint,
|
|
||||||
shouldReturn403WhenNoPermission,
|
|
||||||
shouldReturn200WithOnlyOnePermission,
|
|
||||||
} = require("./couchTestUtils");
|
} = require("./couchTestUtils");
|
||||||
const {
|
|
||||||
WRITE_MODEL, READ_MODEL
|
|
||||||
} = require("../../../utilities/accessLevels")
|
|
||||||
|
|
||||||
describe("/records", () => {
|
describe("/records", () => {
|
||||||
let request
|
let request
|
||||||
|
@ -41,6 +35,8 @@ describe("/records", () => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("save, load, update, delete", () => {
|
||||||
|
|
||||||
const createRecord = async r =>
|
const createRecord = async r =>
|
||||||
await request
|
await request
|
||||||
.post(`/api/${instance._id}/${model._id}/records`)
|
.post(`/api/${instance._id}/${model._id}/records`)
|
||||||
|
@ -49,8 +45,6 @@ describe("/records", () => {
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
describe("save", () => {
|
|
||||||
|
|
||||||
it("returns a success message when the record is created", async () => {
|
it("returns a success message when the record is created", async () => {
|
||||||
const res = await createRecord()
|
const res = await createRecord()
|
||||||
expect(res.res.statusMessage).toEqual(`${model.name} created successfully`)
|
expect(res.res.statusMessage).toEqual(`${model.name} created successfully`)
|
||||||
|
@ -58,18 +52,6 @@ describe("/records", () => {
|
||||||
expect(res.body._rev).toBeDefined()
|
expect(res.body._rev).toBeDefined()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should apply authorization to endpoint", async () => {
|
|
||||||
await testPermissionsForEndpoint({
|
|
||||||
request,
|
|
||||||
method: "POST",
|
|
||||||
url: `/api/${instance._id}/${model._id}/records`,
|
|
||||||
body: record,
|
|
||||||
instanceId: instance._id,
|
|
||||||
permissionName: WRITE_MODEL,
|
|
||||||
itemId: model._id,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it("updates a record successfully", async () => {
|
it("updates a record successfully", async () => {
|
||||||
const rec = await createRecord()
|
const rec = await createRecord()
|
||||||
const existing = rec.body
|
const existing = rec.body
|
||||||
|
@ -89,9 +71,7 @@ describe("/records", () => {
|
||||||
expect(res.res.statusMessage).toEqual(`${model.name} updated successfully.`)
|
expect(res.res.statusMessage).toEqual(`${model.name} updated successfully.`)
|
||||||
expect(res.body.name).toEqual("Updated Name")
|
expect(res.body.name).toEqual("Updated Name")
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
describe("find", () => {
|
|
||||||
it("should load a record", async () => {
|
it("should load a record", async () => {
|
||||||
const rec = await createRecord()
|
const rec = await createRecord()
|
||||||
const existing = rec.body
|
const existing = rec.body
|
||||||
|
@ -110,31 +90,6 @@ describe("/records", () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("load should return 404 when record does not exist", async () => {
|
|
||||||
await createRecord()
|
|
||||||
await request
|
|
||||||
.get(`/api/${instance._id}/${model._id}/records/not-a-valid-id`)
|
|
||||||
.set(defaultHeaders)
|
|
||||||
.expect('Content-Type', /json/)
|
|
||||||
.expect(404)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should apply authorization to endpoint", async () => {
|
|
||||||
const rec = await createRecord()
|
|
||||||
await testPermissionsForEndpoint({
|
|
||||||
request,
|
|
||||||
method: "GET",
|
|
||||||
url: `/api/${instance._id}/${model._id}/records/${rec.body._id}`,
|
|
||||||
instanceId: instance._id,
|
|
||||||
permissionName: READ_MODEL,
|
|
||||||
itemId: model._id,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("fetch", () => {
|
|
||||||
|
|
||||||
it("should list all records for given modelId", async () => {
|
it("should list all records for given modelId", async () => {
|
||||||
const newRecord = {
|
const newRecord = {
|
||||||
modelId: model._id,
|
modelId: model._id,
|
||||||
|
@ -155,47 +110,14 @@ describe("/records", () => {
|
||||||
expect(res.body.find(r => r.name === record.name)).toBeDefined()
|
expect(res.body.find(r => r.name === record.name)).toBeDefined()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should apply authorization to endpoint", async () => {
|
it("load should return 404 when record does not exist", async () => {
|
||||||
await testPermissionsForEndpoint({
|
await createRecord()
|
||||||
request,
|
|
||||||
method: "GET",
|
|
||||||
url: `/api/${instance._id}/${model._id}/records`,
|
|
||||||
instanceId: instance._id,
|
|
||||||
permissionName: READ_MODEL,
|
|
||||||
itemId: model._id,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("delete", () => {
|
|
||||||
|
|
||||||
it("should remove a record", async () => {
|
|
||||||
const createRes = await createRecord()
|
|
||||||
|
|
||||||
await request
|
await request
|
||||||
.delete(`/api/${instance._id}/${model._id}/records/${createRes.body._id}/${createRes.body._rev}`)
|
.get(`/api/${instance._id}/${model._id}/records/not-a-valid-id`)
|
||||||
.set(defaultHeaders)
|
|
||||||
.expect(200)
|
|
||||||
|
|
||||||
await request
|
|
||||||
.get(`/api/${instance._id}/${model._id}/records/${createRes.body._id}`)
|
|
||||||
.set(defaultHeaders)
|
.set(defaultHeaders)
|
||||||
|
.expect('Content-Type', /json/)
|
||||||
.expect(404)
|
.expect(404)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should apply authorization to endpoint", async () => {
|
|
||||||
const createRes = await createRecord()
|
|
||||||
await testPermissionsForEndpoint({
|
|
||||||
request,
|
|
||||||
method: "DELETE",
|
|
||||||
url: `/api/${instance._id}/${model._id}/records/${createRes.body._id}/${createRes.body._rev}`,
|
|
||||||
instanceId: instance._id,
|
|
||||||
permissionName: WRITE_MODEL,
|
|
||||||
itemId: model._id,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("validate", () => {
|
describe("validate", () => {
|
||||||
|
|
|
@ -3,13 +3,9 @@ const {
|
||||||
createApplication,
|
createApplication,
|
||||||
createInstance,
|
createInstance,
|
||||||
createModel,
|
createModel,
|
||||||
createRecord,
|
|
||||||
supertest,
|
supertest,
|
||||||
defaultHeaders,
|
defaultHeaders
|
||||||
testPermissionsForEndpoint,
|
|
||||||
builderEndpointShouldBlockNormalUsers,
|
|
||||||
} = require("./couchTestUtils")
|
} = require("./couchTestUtils")
|
||||||
const { READ_VIEW } = require("../../../utilities/accessLevels")
|
|
||||||
|
|
||||||
describe("/views", () => {
|
describe("/views", () => {
|
||||||
let request
|
let request
|
||||||
|
@ -38,10 +34,11 @@ describe("/views", () => {
|
||||||
.send({
|
.send({
|
||||||
name: "TestView",
|
name: "TestView",
|
||||||
map: `function(doc) {
|
map: `function(doc) {
|
||||||
if (doc.type === 'record') {
|
if (doc.id) {
|
||||||
emit(doc.name, doc._id);
|
emit(doc.name, doc._id);
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
|
reduce: `function(keys, values) { }`
|
||||||
})
|
})
|
||||||
.set(defaultHeaders)
|
.set(defaultHeaders)
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
|
@ -54,28 +51,14 @@ describe("/views", () => {
|
||||||
expect(res.res.statusMessage).toEqual("View TestView created successfully.");
|
expect(res.res.statusMessage).toEqual("View TestView created successfully.");
|
||||||
expect(res.body.name).toEqual("TestView");
|
expect(res.body.name).toEqual("TestView");
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should apply authorization to endpoint", async () => {
|
|
||||||
await builderEndpointShouldBlockNormalUsers({
|
|
||||||
request,
|
|
||||||
method: "POST",
|
|
||||||
url: `/api/${instance._id}/views`,
|
|
||||||
body: {
|
|
||||||
name: "TestView",
|
|
||||||
map: `function(doc) {
|
|
||||||
if (doc.id) {
|
|
||||||
emit(doc.name, doc._id);
|
|
||||||
}
|
|
||||||
}`,
|
|
||||||
reduce: `function(keys, values) { }`
|
|
||||||
},
|
|
||||||
instanceId: instance._id,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("fetch", () => {
|
describe("fetch", () => {
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
model = await createModel(request, instance._id);
|
||||||
|
});
|
||||||
|
|
||||||
it("should only return custom views", async () => {
|
it("should only return custom views", async () => {
|
||||||
const view = await createView()
|
const view = await createView()
|
||||||
const res = await request
|
const res = await request
|
||||||
|
@ -86,46 +69,5 @@ describe("/views", () => {
|
||||||
expect(res.body.length).toBe(1)
|
expect(res.body.length).toBe(1)
|
||||||
expect(res.body.find(v => v.name === view.body.name)).toBeDefined()
|
expect(res.body.find(v => v.name === view.body.name)).toBeDefined()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should apply authorization to endpoint", async () => {
|
|
||||||
await builderEndpointShouldBlockNormalUsers({
|
|
||||||
request,
|
|
||||||
method: "GET",
|
|
||||||
url: `/api/${instance._id}/views`,
|
|
||||||
instanceId: instance._id,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("query", () => {
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
model = await createModel(request, instance._id);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return records from custom view", async () => {
|
|
||||||
await createView()
|
|
||||||
const rec1 = await createRecord({ request, instanceId: instance._id, modelId: model._id })
|
|
||||||
await createRecord({ request, instanceId: instance._id, modelId: model._id })
|
|
||||||
const res = await request
|
|
||||||
.get(`/api/${instance._id}/views/TestView`)
|
|
||||||
.set(defaultHeaders)
|
|
||||||
.expect('Content-Type', /json/)
|
|
||||||
.expect(200)
|
|
||||||
expect(res.body.length).toBe(2)
|
|
||||||
expect(res.body.find(r => r._id === rec1._id)).toBeDefined()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should apply authorization to endpoint", async () => {
|
|
||||||
await createView()
|
|
||||||
await testPermissionsForEndpoint({
|
|
||||||
request,
|
|
||||||
method: "GET",
|
|
||||||
url: `/api/${instance._id}/views/TestView`,
|
|
||||||
instanceId: instance._id,
|
|
||||||
permissionName: READ_VIEW,
|
|
||||||
itemId: "TestView",
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
});
|
});
|
|
@ -125,29 +125,6 @@ describe("/workflows", () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("find", () => {
|
|
||||||
it("returns a workflow when queried by ID", async () => {
|
|
||||||
await createWorkflow();
|
|
||||||
const res = await request
|
|
||||||
.get(`/api/${instance._id}/workflows/${workflow.id}`)
|
|
||||||
.set(defaultHeaders)
|
|
||||||
.expect('Content-Type', /json/)
|
|
||||||
.expect(200)
|
|
||||||
|
|
||||||
expect(res.body).toEqual(expect.objectContaining(TEST_WORKFLOW));
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should apply authorization to endpoint", async () => {
|
|
||||||
await createWorkflow();
|
|
||||||
await builderEndpointShouldBlockNormalUsers({
|
|
||||||
request,
|
|
||||||
method: "GET",
|
|
||||||
url: `/api/${instance._id}/workflows/${workflow.id}`,
|
|
||||||
instanceId: instance._id,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("destroy", () => {
|
describe("destroy", () => {
|
||||||
it("deletes a workflow by its ID", async () => {
|
it("deletes a workflow by its ID", async () => {
|
||||||
await createWorkflow();
|
await createWorkflow();
|
||||||
|
|
Loading…
Reference in New Issue