Test delete
This commit is contained in:
parent
233f54f036
commit
38e718b6f1
|
@ -2,7 +2,7 @@ import * as setup from "../../tests/utilities"
|
||||||
import { checkSlashesInUrl } from "../../../../utilities"
|
import { checkSlashesInUrl } from "../../../../utilities"
|
||||||
import supertest from "supertest"
|
import supertest from "supertest"
|
||||||
|
|
||||||
export type HttpMethod = "post" | "get" | "put"
|
export type HttpMethod = "post" | "get" | "put" | "delete"
|
||||||
|
|
||||||
export type MakeRequestResponse = (
|
export type MakeRequestResponse = (
|
||||||
method: HttpMethod,
|
method: HttpMethod,
|
||||||
|
|
|
@ -149,9 +149,9 @@ describe("row api - postgres", () => {
|
||||||
|
|
||||||
expect(res.status).toBe(200)
|
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({
|
expect.objectContaining({
|
||||||
...res.body.data,
|
...res.body.data,
|
||||||
...rowData,
|
...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", () => {
|
describe("retrieve a row", () => {
|
||||||
test("Given than a table have a single row, the row can be retrieved successfully", async () => {
|
test("Given than a table have a single row, the row can be retrieved successfully", async () => {
|
||||||
const [{ rowData, row }] = await populateRows(1)
|
const [{ rowData, row }] = await populateRows(1)
|
||||||
|
|
Loading…
Reference in New Issue