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