fixing some broken tests

This commit is contained in:
Michael Shanks 2020-09-11 09:29:23 +01:00
parent 95da4c8d2c
commit 3696d4b077
4 changed files with 38 additions and 14 deletions

View File

@ -28,7 +28,8 @@ describe("fetch bindable properties", () => {
...testData()
})
const contextBindings = result.filter(r => r.instance._id === "list-id" && r.type==="context")
expect(contextBindings.length).toBe(2)
// 2 fields + _id + _rev
expect(contextBindings.length).toBe(4)
const namebinding = contextBindings.find(b => b.runtimeBinding === "data.name")
expect(namebinding).toBeDefined()
@ -37,6 +38,10 @@ describe("fetch bindable properties", () => {
const descriptionbinding = contextBindings.find(b => b.runtimeBinding === "data.description")
expect(descriptionbinding).toBeDefined()
expect(descriptionbinding.readableBinding).toBe("list-name.Test Model.description")
const idbinding = contextBindings.find(b => b.runtimeBinding === "data._id")
expect(idbinding).toBeDefined()
expect(idbinding.readableBinding).toBe("list-name.Test Model._id")
})
it("should return model schema, for grantparent context", () => {
@ -45,7 +50,8 @@ describe("fetch bindable properties", () => {
...testData()
})
const contextBindings = result.filter(r => r.type==="context")
expect(contextBindings.length).toBe(4)
// 2 fields + _id + _rev ... x 2 models
expect(contextBindings.length).toBe(8)
const namebinding_parent = contextBindings.find(b => b.runtimeBinding === "parent.data.name")
expect(namebinding_parent).toBeDefined()
@ -120,7 +126,7 @@ const testData = () => {
_id: "list-id",
_component: "@budibase/standard-components/list",
_instanceName: "list-name",
model: "test-model-id",
model: { isModel: true, modelId: "test-model-id", label: "Test Model", name: "all_test-model-id" },
_children: [
{
_id: "list-item-heading-id",
@ -138,7 +144,7 @@ const testData = () => {
_id: "child-list-id",
_component: "@budibase/standard-components/list",
_instanceName: "child-list-name",
model: "test-model-id",
model: { isModel: true, modelId: "test-model-id", label: "Test Model", name: "all_test-model-id"},
_children: [
{
_id: "child-list-item-heading-id",

View File

@ -50,6 +50,7 @@ exports.createModel = async (request, appId, instanceId, model) => {
constraints: {
type: "string",
},
},
description: {
type: "text",
constraints: {
@ -57,7 +58,6 @@ exports.createModel = async (request, appId, instanceId, model) => {
},
},
},
},
}
const res = await request
@ -67,6 +67,18 @@ exports.createModel = async (request, appId, instanceId, model) => {
return res.body
}
exports.createView = async (request, appId, instanceId, view) => {
view = view || {
map: "function(doc) { emit(doc[doc.key], doc._id); } ",
}
const res = await request
.post(`/api/views`)
.set(exports.defaultHeaders(appId, instanceId))
.send(view)
return res.body
}
exports.createClientDatabase = async id => await create(id || TEST_CLIENT_ID)
exports.createApplication = async (request, name = "test_application") => {

View File

@ -160,7 +160,7 @@ describe("/records", () => {
const existing = rec.body
const res = await request
.patch(`/api/${model._id}/records/${rec._id}`)
.patch(`/api/${model._id}/records/${existing._id}`)
.send({
_id: existing._id,
_rev: existing._rev,
@ -173,11 +173,11 @@ describe("/records", () => {
expect(res.res.statusMessage).toEqual(`${model.name} updated successfully.`)
expect(res.body.name).toEqual("Updated Name")
expect(res.body.description).toEqual(rec.description)
expect(res.body.description).toEqual(existing.description)
const savedRecord = await loadRecord(res.body._id)
expect(savedRecord.body.description).toEqual(rec.description)
expect(savedRecord.body.description).toEqual(existing.description)
expect(savedRecord.body.name).toEqual("Updated Name")
})

View File

@ -72,8 +72,14 @@ describe("/views", () => {
type: "text",
constraints: {
type: "string"
}
}
},
},
description: {
type: "text",
constraints: {
type: "string"
},
},
}
}
});