Add update test
This commit is contained in:
parent
ac9ad71a11
commit
233f54f036
|
@ -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"
|
export type HttpMethod = "post" | "get" | "put"
|
||||||
|
|
||||||
export type MakeRequestResponse = (
|
export type MakeRequestResponse = (
|
||||||
method: HttpMethod,
|
method: HttpMethod,
|
||||||
|
|
|
@ -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", () => {
|
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)
|
||||||
|
|
|
@ -472,7 +472,7 @@ class TestConfiguration {
|
||||||
return this._req(config, { tableId }, controllers.row.save)
|
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)
|
return this._req(null, { tableId, rowId }, controllers.row.find)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue