adding renaming test

This commit is contained in:
Martin McKeaveney 2020-06-26 09:55:15 +01:00
parent fb382329b8
commit e293f3f70a
3 changed files with 46 additions and 2 deletions

View File

@ -13,7 +13,7 @@
let linkedRecords = new Set(linked) let linkedRecords = new Set(linked)
$: linked = [...linkedRecords] $: linked = [...linkedRecords]
$: FIELDS_TO_HIDE = [$backendUiStore.selectedModel._id] $: FIELDS_TO_HIDE = [$backendUiStore.selectedModel.name]
$: schema = $backendUiStore.selectedModel.schema $: schema = $backendUiStore.selectedModel.schema
async function fetchRecords() { async function fetchRecords() {

View File

@ -44,5 +44,6 @@
-moz-box-sizing: border-box; -moz-box-sizing: border-box;
-webkit-box-sizing: border-box; -webkit-box-sizing: border-box;
box-sizing: border-box; box-sizing: border-box;
font-family: Inter;
} }
</style> </style>

View File

@ -26,7 +26,6 @@ describe("/models", () => {
}) })
describe("create", () => { describe("create", () => {
beforeEach(async () => { beforeEach(async () => {
instance = await createInstance(request, app._id); 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 () => { it("should apply authorization to endpoint", async () => {
await builderEndpointShouldBlockNormalUsers({ await builderEndpointShouldBlockNormalUsers({
request, request,