From 233f54f0368c97c3bcfab745293376c166689108 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 18 Jan 2023 17:11:52 +0000 Subject: [PATCH] Add update test --- .../src/api/routes/public/tests/utils.ts | 2 +- .../server/src/integration-test/row.spec.ts | 31 +++++++++++++++++++ .../src/tests/utilities/TestConfiguration.ts | 2 +- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/packages/server/src/api/routes/public/tests/utils.ts b/packages/server/src/api/routes/public/tests/utils.ts index 8e7c6e187c..8f798cb587 100644 --- a/packages/server/src/api/routes/public/tests/utils.ts +++ b/packages/server/src/api/routes/public/tests/utils.ts @@ -2,7 +2,7 @@ import * as setup from "../../tests/utilities" import { checkSlashesInUrl } from "../../../../utilities" import supertest from "supertest" -export type HttpMethod = "post" | "get" +export type HttpMethod = "post" | "get" | "put" export type MakeRequestResponse = ( method: HttpMethod, diff --git a/packages/server/src/integration-test/row.spec.ts b/packages/server/src/integration-test/row.spec.ts index d620b24548..27e413ea35 100644 --- a/packages/server/src/integration-test/row.spec.ts +++ b/packages/server/src/integration-test/row.spec.ts @@ -130,6 +130,37 @@ describe("row api - postgres", () => { }) }) + describe("update a row", () => { + test("Given than a row exists, updating it persists it", async () => { + let { rowData, row } = _.sample(await populateRows(10))! + + const newName = faker.random.words(3) + const newValue = +faker.random.numeric() + const updateRow = { + name: newName, + value: newValue, + } + + const res = await makeRequest( + "put", + `/tables/${postgresTable._id}/rows/${row._id}`, + updateRow + ) + + expect(res.status).toBe(200) + + const persistedRows = await config.getRow(postgresTable._id!, row._id!) + + expect(persistedRows).toEqual( + expect.objectContaining({ + ...res.body.data, + ...rowData, + ...updateRow, + }) + ) + }) + }) + describe("retrieve a row", () => { test("Given than a table have a single row, the row can be retrieved successfully", async () => { const [{ rowData, row }] = await populateRows(1) diff --git a/packages/server/src/tests/utilities/TestConfiguration.ts b/packages/server/src/tests/utilities/TestConfiguration.ts index 993d5a788f..74e580d8df 100644 --- a/packages/server/src/tests/utilities/TestConfiguration.ts +++ b/packages/server/src/tests/utilities/TestConfiguration.ts @@ -472,7 +472,7 @@ class TestConfiguration { return this._req(config, { tableId }, controllers.row.save) } - async getRow(tableId: string, rowId: string) { + async getRow(tableId: string, rowId: string): Promise { return this._req(null, { tableId, rowId }, controllers.row.find) }