From f4e14db22a361ee1dd9b5d6696a0ccc2592ceff0 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 7 Jun 2024 10:54:14 +0200 Subject: [PATCH] Add failing test --- .../server/src/api/routes/tests/row.spec.ts | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index 4801ac4c55..ccfd3891c5 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -38,7 +38,7 @@ describe.each([ [DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)], [DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)], [DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)], -])("/rows (%s)", (__, dsProvider) => { +])("/rows (%s)", (providerType, dsProvider) => { const isInternal = dsProvider === undefined const config = setup.getConfig() @@ -693,6 +693,49 @@ describe.each([ }) expect(resp.relationship.length).toBe(1) }) + + !isInternal && + // TODO: SQL is having issues creating composite keys + providerType !== DatabaseName.SQL_SERVER && + it("should support updating fields that are part of a composite key", async () => { + const tableRequest = saveTableRequest({ + primary: ["number", "string"], + schema: { + string: { + type: FieldType.STRING, + name: "string", + }, + number: { + type: FieldType.NUMBER, + name: "number", + }, + }, + }) + + delete tableRequest.schema.id + + const table = await config.api.table.save(tableRequest) + + const stringValue = generator.word() + const naturalValue = generator.integer({ min: 0, max: 1000 }) + + const existing = await config.api.row.save(table._id!, { + string: stringValue, + number: naturalValue, + }) + + expect(existing._id).toEqual(`%5B${naturalValue}%2C'${stringValue}'%5D`) + + const row = await config.api.row.patch(table._id!, { + _id: existing._id!, + _rev: existing._rev!, + tableId: table._id!, + string: stringValue, + number: 1500, + }) + + expect(row._id).toEqual(`%5B${"1500"}%2C'${stringValue}'%5D`) + }) }) describe("destroy", () => {