diff --git a/packages/server/src/api/routes/public/tests/utils.ts b/packages/server/src/api/routes/public/tests/utils.ts index 8f798cb587..5850fd9e2e 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" | "put" +export type HttpMethod = "post" | "get" | "put" | "delete" 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 27e413ea35..31f3a138f2 100644 --- a/packages/server/src/integration-test/row.spec.ts +++ b/packages/server/src/integration-test/row.spec.ts @@ -149,9 +149,9 @@ describe("row api - postgres", () => { expect(res.status).toBe(200) - const persistedRows = await config.getRow(postgresTable._id!, row._id!) + const persistedRow = await config.getRow(postgresTable._id!, row._id!) - expect(persistedRows).toEqual( + expect(persistedRow).toEqual( expect.objectContaining({ ...res.body.data, ...rowData, @@ -161,6 +161,28 @@ describe("row api - postgres", () => { }) }) + describe("delete a row", () => { + test("Given than a row exists, delete request removes it", async () => { + const numberOfInitialRows = 5 + let { row } = _.sample(await populateRows(numberOfInitialRows))! + + const res = await makeRequest( + "delete", + `/tables/${postgresTable._id}/rows/${row._id}` + ) + + expect(res.status).toBe(200) + + const persistedRows = await config.getRows(postgresTable._id!) + expect(persistedRows).toHaveLength(numberOfInitialRows - 1) + + expect(row._id).toBeDefined() + expect(persistedRows).not.toContain( + expect.objectContaining({ _id: row._id }) + ) + }) + }) + 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)