diff --git a/packages/server/src/api/routes/tests/table.spec.ts b/packages/server/src/api/routes/tests/table.spec.ts index e47181e21f..2a7f039ff5 100644 --- a/packages/server/src/api/routes/tests/table.spec.ts +++ b/packages/server/src/api/routes/tests/table.spec.ts @@ -185,6 +185,62 @@ if (descriptions.length) { ) } ) + + it("can set primary display", async () => { + const columnName = generator.word() + const table = await config.api.table.save( + tableForDatasource(datasource, { + primaryDisplay: columnName, + schema: { + [columnName]: { + name: columnName, + type: FieldType.STRING, + }, + }, + }) + ) + expect(table.primaryDisplay).toEqual(columnName) + + const res = await config.api.table.get(table._id!) + expect(res.primaryDisplay).toEqual(columnName) + }) + + it("cannot use unexisting columns as primary display", async () => { + const columnName = generator.word() + await config.api.table.save( + tableForDatasource(datasource, { + primaryDisplay: columnName, + }), + { + status: 400, + body: { + message: `Column "${columnName}" cannot be used as a display type.`, + }, + } + ) + }) + + it("cannot use invalid column types as display name", async () => { + const columnName = generator.word() + + await config.api.table.save( + tableForDatasource(datasource, { + primaryDisplay: columnName, + schema: { + [columnName]: { + name: columnName, + type: FieldType.BOOLEAN, + }, + }, + }), + { + status: 400, + body: { + message: `Column "${columnName}" cannot be used as a display type.`, + }, + } + ) + }) }) describe("permissions", () => { @@ -603,6 +659,49 @@ if (descriptions.length) { } expect(response).toEqual(expectedResponse) }) + + it("cannot use unexisting columns as primary display", async () => { + const table = await config.api.table.save( + tableForDatasource(datasource) + ) + + const columnName = generator.word() + const tableRequest = { + ...table, + primaryDisplay: columnName, + } + await config.api.table.save(tableRequest, { + status: 400, + body: { + message: `Column "${columnName}" cannot be used as a display type.`, + }, + }) + }) + + it("cannot use invalid column types as display name", async () => { + const table = await config.api.table.save( + tableForDatasource(datasource) + ) + const columnName = generator.word() + const tableRequest: SaveTableRequest = { + ...table, + primaryDisplay: columnName, + schema: { + ...table.schema, + [columnName]: { + name: columnName, + type: FieldType.BOOLEAN, + }, + }, + } + + await config.api.table.save(tableRequest, { + status: 400, + body: { + message: `Column "${columnName}" cannot be used as a display type.`, + }, + }) + }) }) describe("import", () => {