Add update test

This commit is contained in:
Adria Navarro 2023-01-18 17:11:52 +00:00
parent ac9ad71a11
commit 233f54f036
3 changed files with 33 additions and 2 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"
export type HttpMethod = "post" | "get" | "put"
export type MakeRequestResponse = (
method: HttpMethod,

View File

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

View File

@ -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<Row> {
return this._req(null, { tableId, rowId }, controllers.row.find)
}