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

View File

@ -50,6 +50,7 @@ exports.createModel = async (request, appId, instanceId, model) => {
constraints: { constraints: {
type: "string", type: "string",
}, },
},
description: { description: {
type: "text", type: "text",
constraints: { constraints: {
@ -57,7 +58,6 @@ exports.createModel = async (request, appId, instanceId, model) => {
}, },
}, },
}, },
},
} }
const res = await request const res = await request
@ -67,6 +67,18 @@ exports.createModel = async (request, appId, instanceId, model) => {
return res.body 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.createClientDatabase = async id => await create(id || TEST_CLIENT_ID)
exports.createApplication = async (request, name = "test_application") => { exports.createApplication = async (request, name = "test_application") => {

View File

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

View File

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