Test delete

This commit is contained in:
Adria Navarro 2023-01-18 17:21:17 +00:00
parent 233f54f036
commit 38e718b6f1
2 changed files with 25 additions and 3 deletions

View File

@ -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,

View File

@ -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)