Add another test to make sure relationships are cleared when asked.
This commit is contained in:
parent
965efeaff4
commit
f21addeb71
|
@ -10,6 +10,7 @@ import {
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
|
||||||
import * as setup from "./utilities"
|
import * as setup from "./utilities"
|
||||||
|
import * as uuid from "uuid"
|
||||||
|
|
||||||
describe("test the update row action", () => {
|
describe("test the update row action", () => {
|
||||||
let table: Table, row: Row, inputs: any
|
let table: Table, row: Row, inputs: any
|
||||||
|
@ -67,13 +68,13 @@ describe("test the update row action", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
let table = await config.api.table.create({
|
let table = await config.api.table.create({
|
||||||
name: "TestTable",
|
name: uuid.v4(),
|
||||||
type: "table",
|
type: "table",
|
||||||
sourceType: TableSourceType.INTERNAL,
|
sourceType: TableSourceType.INTERNAL,
|
||||||
sourceId: INTERNAL_TABLE_SOURCE_ID,
|
sourceId: INTERNAL_TABLE_SOURCE_ID,
|
||||||
schema: {
|
schema: {
|
||||||
user1: { ...linkField, name: "user1", fieldName: "user1" },
|
user1: { ...linkField, name: "user1", fieldName: uuid.v4() },
|
||||||
user2: { ...linkField, name: "user2", fieldName: "user2" },
|
user2: { ...linkField, name: "user2", fieldName: uuid.v4() },
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -95,7 +96,8 @@ describe("test the update row action", () => {
|
||||||
_id: row._id,
|
_id: row._id,
|
||||||
_rev: row._rev,
|
_rev: row._rev,
|
||||||
tableId: row.tableId,
|
tableId: row.tableId,
|
||||||
user1: [{ _id: user2._id }],
|
user1: [user2._id],
|
||||||
|
user2: "",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
expect(stepResp.success).toEqual(true)
|
expect(stepResp.success).toEqual(true)
|
||||||
|
@ -104,4 +106,64 @@ describe("test the update row action", () => {
|
||||||
expect(getResp.body.user1[0]._id).toEqual(user2._id)
|
expect(getResp.body.user1[0]._id).toEqual(user2._id)
|
||||||
expect(getResp.body.user2[0]._id).toEqual(user2._id)
|
expect(getResp.body.user2[0]._id).toEqual(user2._id)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should overwrite links if those links are not set and we ask it do", async () => {
|
||||||
|
let linkField: FieldSchema = {
|
||||||
|
type: FieldType.LINK,
|
||||||
|
name: "",
|
||||||
|
fieldName: "",
|
||||||
|
constraints: {
|
||||||
|
type: "array",
|
||||||
|
presence: false,
|
||||||
|
},
|
||||||
|
relationshipType: RelationshipType.ONE_TO_MANY,
|
||||||
|
tableId: InternalTable.USER_METADATA,
|
||||||
|
}
|
||||||
|
|
||||||
|
let table = await config.api.table.create({
|
||||||
|
name: uuid.v4(),
|
||||||
|
type: "table",
|
||||||
|
sourceType: TableSourceType.INTERNAL,
|
||||||
|
sourceId: INTERNAL_TABLE_SOURCE_ID,
|
||||||
|
schema: {
|
||||||
|
user1: { ...linkField, name: "user1", fieldName: uuid.v4() },
|
||||||
|
user2: { ...linkField, name: "user2", fieldName: uuid.v4() },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
let user1 = await config.createUser()
|
||||||
|
let user2 = await config.createUser()
|
||||||
|
|
||||||
|
let row = await config.api.row.save(table._id!, {
|
||||||
|
user1: [{ _id: user1._id }],
|
||||||
|
user2: [{ _id: user2._id }],
|
||||||
|
})
|
||||||
|
|
||||||
|
let getResp = await config.api.row.get(table._id!, row._id!)
|
||||||
|
expect(getResp.body.user1[0]._id).toEqual(user1._id)
|
||||||
|
expect(getResp.body.user2[0]._id).toEqual(user2._id)
|
||||||
|
|
||||||
|
let stepResp = await setup.runStep(setup.actions.UPDATE_ROW.stepId, {
|
||||||
|
rowId: row._id,
|
||||||
|
row: {
|
||||||
|
_id: row._id,
|
||||||
|
_rev: row._rev,
|
||||||
|
tableId: row.tableId,
|
||||||
|
user1: [user2._id],
|
||||||
|
user2: "",
|
||||||
|
},
|
||||||
|
meta: {
|
||||||
|
fields: {
|
||||||
|
user2: {
|
||||||
|
clearRelationships: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
expect(stepResp.success).toEqual(true)
|
||||||
|
|
||||||
|
getResp = await config.api.row.get(table._id!, row._id!)
|
||||||
|
expect(getResp.body.user1[0]._id).toEqual(user2._id)
|
||||||
|
expect(getResp.body.user2).toBeUndefined()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -22,7 +22,15 @@ export class TableAPI extends TestAPI {
|
||||||
.send(data)
|
.send(data)
|
||||||
.set(this.config.defaultHeaders())
|
.set(this.config.defaultHeaders())
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(expectStatus)
|
|
||||||
|
if (res.status !== expectStatus) {
|
||||||
|
throw new Error(
|
||||||
|
`Expected status ${expectStatus} but got ${
|
||||||
|
res.status
|
||||||
|
} with body ${JSON.stringify(res.body)}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return res.body
|
return res.body
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue