From a5972328144a814f0988f672cb3bb966f7cd553a Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Fri, 26 Jun 2020 09:55:15 +0100 Subject: [PATCH] adding renaming test --- .../common/LinkedRecordSelector.svelte | 2 +- .../src/components/common/ValuesList.svelte | 1 + .../server/src/api/routes/tests/model.spec.js | 45 ++++++++++++++++++- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/packages/builder/src/components/common/LinkedRecordSelector.svelte b/packages/builder/src/components/common/LinkedRecordSelector.svelte index a494abc805..715282efea 100644 --- a/packages/builder/src/components/common/LinkedRecordSelector.svelte +++ b/packages/builder/src/components/common/LinkedRecordSelector.svelte @@ -13,7 +13,7 @@ let linkedRecords = new Set(linked) $: linked = [...linkedRecords] - $: FIELDS_TO_HIDE = [$backendUiStore.selectedModel._id] + $: FIELDS_TO_HIDE = [$backendUiStore.selectedModel.name] $: schema = $backendUiStore.selectedModel.schema async function fetchRecords() { diff --git a/packages/builder/src/components/common/ValuesList.svelte b/packages/builder/src/components/common/ValuesList.svelte index f27bf4cf82..4f161247a8 100644 --- a/packages/builder/src/components/common/ValuesList.svelte +++ b/packages/builder/src/components/common/ValuesList.svelte @@ -44,5 +44,6 @@ -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; + font-family: Inter; } diff --git a/packages/server/src/api/routes/tests/model.spec.js b/packages/server/src/api/routes/tests/model.spec.js index 89aa9aa25b..49f6be41ad 100644 --- a/packages/server/src/api/routes/tests/model.spec.js +++ b/packages/server/src/api/routes/tests/model.spec.js @@ -26,7 +26,6 @@ describe("/models", () => { }) describe("create", () => { - beforeEach(async () => { instance = await createInstance(request, app._id); }); @@ -51,6 +50,50 @@ describe("/models", () => { }); }) + it("renames all the record fields for a model when a schema key is renamed", async () => { + const testModel = await createModel(request, app._id, instance._id); + + const testRecord = await request + .post(`/api/${testModel._id}/records`) + .send({ + name: "test" + }) + .set(defaultHeaders(app._id, instance._id)) + .expect('Content-Type', /json/) + .expect(200) + + const updatedModel = await request + .post(`/api/models`) + .send({ + _id: testModel._id, + _rev: testModel._rev, + name: "TestModel", + key: "name", + _rename: { + old: "name", + updated: "updatedName" + }, + schema: { + updatedName: { type: "string" } + } + }) + .set(defaultHeaders(app._id, instance._id)) + .expect('Content-Type', /json/) + .expect(200) + + expect(updatedModel.res.statusMessage).toEqual("Model TestModel saved successfully."); + expect(updatedModel.body.name).toEqual("TestModel"); + + const res = await request + .get(`/api/${testModel._id}/records/${testRecord.body._id}`) + .set(defaultHeaders(app._id, instance._id)) + .expect('Content-Type', /json/) + .expect(200) + + expect(res.body.updatedName).toEqual("test"); + expect(res.body.name).toBeUndefined(); + }); + it("should apply authorization to endpoint", async () => { await builderEndpointShouldBlockNormalUsers({ request,