diff --git a/packages/builder/tests/fetchBindableProperties.spec.js b/packages/builder/tests/fetchBindableProperties.spec.js index 052d98d8ea..76e8e33f05 100644 --- a/packages/builder/tests/fetchBindableProperties.spec.js +++ b/packages/builder/tests/fetchBindableProperties.spec.js @@ -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", diff --git a/packages/server/src/api/routes/tests/couchTestUtils.js b/packages/server/src/api/routes/tests/couchTestUtils.js index 513e1d3f03..ddeab96ade 100644 --- a/packages/server/src/api/routes/tests/couchTestUtils.js +++ b/packages/server/src/api/routes/tests/couchTestUtils.js @@ -50,11 +50,11 @@ exports.createModel = async (request, appId, instanceId, model) => { constraints: { type: "string", }, - description: { - type: "text", - constraints: { - type: "string", - }, + }, + description: { + type: "text", + constraints: { + type: "string", }, }, }, @@ -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") => { diff --git a/packages/server/src/api/routes/tests/record.spec.js b/packages/server/src/api/routes/tests/record.spec.js index 68e9f8758f..1944499e0f 100644 --- a/packages/server/src/api/routes/tests/record.spec.js +++ b/packages/server/src/api/routes/tests/record.spec.js @@ -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") }) diff --git a/packages/server/src/api/routes/tests/view.spec.js b/packages/server/src/api/routes/tests/view.spec.js index a8daa73f64..ac8ade122f 100644 --- a/packages/server/src/api/routes/tests/view.spec.js +++ b/packages/server/src/api/routes/tests/view.spec.js @@ -72,8 +72,14 @@ describe("/views", () => { type: "text", constraints: { type: "string" - } - } + }, + }, + description: { + type: "text", + constraints: { + type: "string" + }, + }, } } });