Fix tests
This commit is contained in:
parent
c6621e8c49
commit
f8adbb86a0
|
@ -109,7 +109,13 @@ export async function save(ctx: UserCtx) {
|
||||||
export async function find(ctx: UserCtx): Promise<Row> {
|
export async function find(ctx: UserCtx): Promise<Row> {
|
||||||
const id = ctx.params.rowId
|
const id = ctx.params.rowId
|
||||||
const tableId = utils.getTableId(ctx)
|
const tableId = utils.getTableId(ctx)
|
||||||
return sdk.rows.external.getRow(tableId, id)
|
const row = await sdk.rows.external.getRow(tableId, id)
|
||||||
|
|
||||||
|
if (!row) {
|
||||||
|
ctx.throw(404)
|
||||||
|
}
|
||||||
|
|
||||||
|
return row
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function destroy(ctx: UserCtx) {
|
export async function destroy(ctx: UserCtx) {
|
||||||
|
|
|
@ -12,6 +12,7 @@ import {
|
||||||
PermissionLevel,
|
PermissionLevel,
|
||||||
QuotaUsageType,
|
QuotaUsageType,
|
||||||
Row,
|
Row,
|
||||||
|
SaveRowRequest,
|
||||||
SaveTableRequest,
|
SaveTableRequest,
|
||||||
SortOrder,
|
SortOrder,
|
||||||
SortType,
|
SortType,
|
||||||
|
@ -34,6 +35,8 @@ describe.each([
|
||||||
["internal", undefined],
|
["internal", undefined],
|
||||||
["postgres", databaseTestProviders.postgres],
|
["postgres", databaseTestProviders.postgres],
|
||||||
])("/rows (%s)", (_, dsProvider) => {
|
])("/rows (%s)", (_, dsProvider) => {
|
||||||
|
const isInternal = !dsProvider
|
||||||
|
|
||||||
let request = setup.getRequest()
|
let request = setup.getRequest()
|
||||||
let config = setup.getConfig()
|
let config = setup.getConfig()
|
||||||
let table: Table
|
let table: Table
|
||||||
|
@ -127,9 +130,20 @@ describe.each([
|
||||||
expect(usage).toBe(expected)
|
expect(usage).toBe(expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
const createRow = () => config.api.row.save(table._id!, basicRow(table._id!))
|
const createRow = (row?: SaveRowRequest) =>
|
||||||
|
config.api.row.save(table._id!, row || basicRow(table._id!))
|
||||||
|
|
||||||
describe("save, load, update", () => {
|
describe("save, load, update", () => {
|
||||||
|
function getDefaultFields() {
|
||||||
|
if (isInternal) {
|
||||||
|
return {
|
||||||
|
type: "row",
|
||||||
|
createdAt: timestamp,
|
||||||
|
updatedAt: timestamp,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
it("returns a success message when the row is created", async () => {
|
it("returns a success message when the row is created", async () => {
|
||||||
const rowUsage = await getRowUsage()
|
const rowUsage = await getRowUsage()
|
||||||
const queryUsage = await getQueryUsage()
|
const queryUsage = await getQueryUsage()
|
||||||
|
@ -230,7 +244,7 @@ describe.each([
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should load a row", async () => {
|
it("should load a row", async () => {
|
||||||
const existing = await config.createRow()
|
const existing = await createRow()
|
||||||
const queryUsage = await getQueryUsage()
|
const queryUsage = await getQueryUsage()
|
||||||
|
|
||||||
const res = await request
|
const res = await request
|
||||||
|
@ -243,9 +257,8 @@ describe.each([
|
||||||
...row,
|
...row,
|
||||||
_id: existing._id,
|
_id: existing._id,
|
||||||
_rev: existing._rev,
|
_rev: existing._rev,
|
||||||
type: "row",
|
id: existing.id,
|
||||||
createdAt: timestamp,
|
...getDefaultFields(),
|
||||||
updatedAt: timestamp,
|
|
||||||
})
|
})
|
||||||
await assertQueryUsage(queryUsage + 1)
|
await assertQueryUsage(queryUsage + 1)
|
||||||
})
|
})
|
||||||
|
@ -256,8 +269,8 @@ describe.each([
|
||||||
name: "Second Contact",
|
name: "Second Contact",
|
||||||
status: "new",
|
status: "new",
|
||||||
}
|
}
|
||||||
await config.createRow()
|
await createRow()
|
||||||
await config.createRow(newRow)
|
await createRow(newRow)
|
||||||
const queryUsage = await getQueryUsage()
|
const queryUsage = await getQueryUsage()
|
||||||
|
|
||||||
const res = await request
|
const res = await request
|
||||||
|
@ -273,14 +286,12 @@ describe.each([
|
||||||
})
|
})
|
||||||
|
|
||||||
it("load should return 404 when row does not exist", async () => {
|
it("load should return 404 when row does not exist", async () => {
|
||||||
await config.createRow()
|
await createRow()
|
||||||
const queryUsage = await getQueryUsage()
|
const queryUsage = await getQueryUsage()
|
||||||
|
|
||||||
await request
|
await config.api.row.get(table._id!, "1234567", {
|
||||||
.get(`/api/${table._id}/rows/not-a-valid-id`)
|
expectStatus: 404,
|
||||||
.set(config.defaultHeaders())
|
})
|
||||||
.expect("Content-Type", /json/)
|
|
||||||
.expect(404)
|
|
||||||
await assertQueryUsage(queryUsage) // no change
|
await assertQueryUsage(queryUsage) // no change
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue