Skip to content

Commit

Permalink
Add extra test
Browse files Browse the repository at this point in the history
  • Loading branch information
adrinr committed Sep 3, 2024
1 parent 662c6be commit 3a3151b
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions packages/server/src/api/routes/tests/viewV2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,101 @@ describe.each([
})
)
})

it("updates all views references", async () => {
let auxTable = await config.api.table.save(
saveTableRequest({
primaryDisplay: "name",
schema: {
name: { name: "name", type: FieldType.STRING },
age: { name: "age", type: FieldType.NUMBER },
},
})
)

const createTableWithRelationship = async () => {
const table = await config.api.table.save(
saveTableRequest({
schema: {},
})
)
await config.api.table.save({
...table,
schema: {
...table.schema,
aux: {
name: "aux",
relationshipType: RelationshipType.ONE_TO_MANY,
type: FieldType.LINK,
tableId: auxTable._id!,
fieldName: `fk_${table.name}`,
constraints: { type: "array" },
},
},
})

return table
}

const table1 = await createTableWithRelationship()
const table2 = await createTableWithRelationship()

// Refetch auxTable
auxTable = await config.api.table.get(auxTable._id!)

const createView = async (tableId: string) => {
const view = await config.api.viewV2.create({
name: generator.guid(),
tableId,
schema: {
aux: {
visible: true,
columns: {
name: { visible: true, readonly: true },
age: { visible: true, readonly: true },
},
},
},
})
return view
}

const view1 = await createView(table1._id!)
const view2 = await createView(table1._id!)
const view3 = await createView(table2._id!)

await config.api.table.save({
...auxTable,
schema: {
...auxTable.schema,
// @ts-ignore deleting age to force the rename
age: undefined,
dob: {
name: "dob",
type: FieldType.NUMBER,
constraints: { presence: true },
},
},
_rename: { old: "age", updated: "dob" },
})

for (const view of [view1, view2, view3]) {
const updatedView = await config.api.viewV2.get(view.id)
expect(updatedView).toEqual(
expect.objectContaining({
schema: expect.objectContaining({
aux: expect.objectContaining({
columns: {
id: { visible: false, readonly: false },
name: { visible: true, readonly: true },
dob: { visible: true, readonly: true },
},
}),
}),
})
)
}
})
})
})
})
Expand Down

0 comments on commit 3a3151b

Please sign in to comment.