Skip to content

Commit

Permalink
Add renaming column tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adrinr committed Sep 2, 2024
1 parent fc3684c commit 2365a6e
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions packages/server/src/api/routes/tests/viewV2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
ViewV2,
SearchResponse,
BasicOperator,
RelationshipType,
} from "@budibase/types"
import { generator, mocks } from "@budibase/backend-core/tests"
import { DatabaseName, getDatasource } from "../../../integrations/tests/utils"
Expand Down Expand Up @@ -1176,6 +1177,87 @@ describe.each([
}
)
})

it("updating a column will update link columns configuration", async () => {
let auxTable = await config.api.table.save(
saveTableRequest({
primaryDisplay: "name",
schema: {
name: {
name: "name",
type: FieldType.STRING,
constraints: { presence: true },
},
age: {
name: "age",
type: FieldType.NUMBER,
constraints: { presence: true },
},
},
})
)

const table = await config.api.table.save(
saveTableRequest({
schema: {
aux: {
name: "aux",
relationshipType: RelationshipType.ONE_TO_MANY,
type: FieldType.LINK,
tableId: auxTable._id!,
fieldName: "fk_aux",
constraints: { presence: true },
},
},
})
)

const view = await config.api.viewV2.create({
name: "view a",
tableId: table._id!,
schema: {
aux: {
visible: true,
columns: {
name: { visible: true, readonly: true },
age: { visible: true, readonly: true },
},
},
},
})

// Refetch autTable
auxTable = await config.api.table.get(auxTable._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" },
})

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 2365a6e

Please sign in to comment.