Add "get" tests
This commit is contained in:
parent
df418daf40
commit
39f3cc57eb
|
@ -229,12 +229,12 @@ describe("row api - postgres", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("search for rows", () => {
|
describe("search for rows", () => {
|
||||||
|
const search = (tableId: string | undefined, body?: object) =>
|
||||||
|
makeRequest("post", `/tables/${postgresTable._id}/rows/search`, body)
|
||||||
|
|
||||||
describe("empty search", () => {
|
describe("empty search", () => {
|
||||||
test("Given than a table has no rows, search without query returns empty", async () => {
|
test("Given than a table has no rows, search without query returns empty", async () => {
|
||||||
const res = await makeRequest(
|
const res = await search(postgresTable._id)
|
||||||
"post",
|
|
||||||
`/tables/${postgresTable._id}/rows/search`
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(res.status).toBe(200)
|
expect(res.status).toBe(200)
|
||||||
|
|
||||||
|
@ -245,10 +245,7 @@ describe("row api - postgres", () => {
|
||||||
const rowsCount = 6
|
const rowsCount = 6
|
||||||
const rows = await populateRows(rowsCount)
|
const rows = await populateRows(rowsCount)
|
||||||
|
|
||||||
const res = await makeRequest(
|
const res = await search(postgresTable._id)
|
||||||
"post",
|
|
||||||
`/tables/${postgresTable._id}/rows/search`
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(res.status).toBe(200)
|
expect(res.status).toBe(200)
|
||||||
|
|
||||||
|
@ -266,10 +263,7 @@ describe("row api - postgres", () => {
|
||||||
await populateRows(rowsCount)
|
await populateRows(rowsCount)
|
||||||
await populateRows(2, (await config.createTable())._id)
|
await populateRows(2, (await config.createTable())._id)
|
||||||
|
|
||||||
const res = await makeRequest(
|
const res = await search(postgresTable._id)
|
||||||
"post",
|
|
||||||
`/tables/${postgresTable._id}/rows/search`
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(res.status).toBe(200)
|
expect(res.status).toBe(200)
|
||||||
|
|
||||||
|
@ -298,17 +292,13 @@ describe("row api - postgres", () => {
|
||||||
}
|
}
|
||||||
await populateRows(1)
|
await populateRows(1)
|
||||||
|
|
||||||
const res = await makeRequest(
|
const res = await search(postgresTable._id, {
|
||||||
"post",
|
query: {
|
||||||
`/tables/${postgresTable._id}/rows/search`,
|
string: {
|
||||||
{
|
name,
|
||||||
query: {
|
|
||||||
string: {
|
|
||||||
name,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
)
|
})
|
||||||
|
|
||||||
expect(res.status).toBe(200)
|
expect(res.status).toBe(200)
|
||||||
|
|
||||||
|
@ -321,13 +311,9 @@ describe("row api - postgres", () => {
|
||||||
test("Querying respects the limit fields", async () => {
|
test("Querying respects the limit fields", async () => {
|
||||||
await populateRows(6)
|
await populateRows(6)
|
||||||
|
|
||||||
const res = await makeRequest(
|
const res = await search(postgresTable._id, {
|
||||||
"post",
|
limit: 2,
|
||||||
`/tables/${postgresTable._id}/rows/search`,
|
})
|
||||||
{
|
|
||||||
limit: 2,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(res.status).toBe(200)
|
expect(res.status).toBe(200)
|
||||||
|
|
||||||
|
@ -361,17 +347,13 @@ describe("row api - postgres", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
test("Querying respects the sort order when sorting ascending by a string value", async () => {
|
test("Querying respects the sort order when sorting ascending by a string value", async () => {
|
||||||
const res = await makeRequest(
|
const res = await search(postgresTable._id, {
|
||||||
"post",
|
sort: {
|
||||||
`/tables/${postgresTable._id}/rows/search`,
|
order: "ascending",
|
||||||
{
|
column: "name",
|
||||||
sort: {
|
type: "string",
|
||||||
order: "ascending",
|
},
|
||||||
column: "name",
|
})
|
||||||
type: "string",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(res.status).toBe(200)
|
expect(res.status).toBe(200)
|
||||||
expect(res.body.data).toEqual([
|
expect(res.body.data).toEqual([
|
||||||
|
@ -383,17 +365,13 @@ describe("row api - postgres", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
test("Querying respects the sort order when sorting descending by a string value", async () => {
|
test("Querying respects the sort order when sorting descending by a string value", async () => {
|
||||||
const res = await makeRequest(
|
const res = await search(postgresTable._id, {
|
||||||
"post",
|
sort: {
|
||||||
`/tables/${postgresTable._id}/rows/search`,
|
order: "descending",
|
||||||
{
|
column: "name",
|
||||||
sort: {
|
type: "string",
|
||||||
order: "descending",
|
},
|
||||||
column: "name",
|
})
|
||||||
type: "string",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(res.status).toBe(200)
|
expect(res.status).toBe(200)
|
||||||
expect(res.body.data).toEqual([
|
expect(res.body.data).toEqual([
|
||||||
|
@ -405,17 +383,13 @@ describe("row api - postgres", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
test("Querying respects the sort order when sorting ascending by a numeric value", async () => {
|
test("Querying respects the sort order when sorting ascending by a numeric value", async () => {
|
||||||
const res = await makeRequest(
|
const res = await search(postgresTable._id, {
|
||||||
"post",
|
sort: {
|
||||||
`/tables/${postgresTable._id}/rows/search`,
|
order: "ascending",
|
||||||
{
|
column: "value",
|
||||||
sort: {
|
type: "number",
|
||||||
order: "ascending",
|
},
|
||||||
column: "value",
|
})
|
||||||
type: "number",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(res.status).toBe(200)
|
expect(res.status).toBe(200)
|
||||||
expect(res.body.data).toEqual([
|
expect(res.body.data).toEqual([
|
||||||
|
@ -427,17 +401,13 @@ describe("row api - postgres", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
test("Querying respects the sort order when sorting descending by a numeric value", async () => {
|
test("Querying respects the sort order when sorting descending by a numeric value", async () => {
|
||||||
const res = await makeRequest(
|
const res = await search(postgresTable._id, {
|
||||||
"post",
|
sort: {
|
||||||
`/tables/${postgresTable._id}/rows/search`,
|
order: "descending",
|
||||||
{
|
column: "value",
|
||||||
sort: {
|
type: "number",
|
||||||
order: "descending",
|
},
|
||||||
column: "value",
|
})
|
||||||
type: "number",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(res.status).toBe(200)
|
expect(res.status).toBe(200)
|
||||||
expect(res.body.data).toEqual([
|
expect(res.body.data).toEqual([
|
||||||
|
@ -449,4 +419,46 @@ describe("row api - postgres", () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("get all rows", () => {
|
||||||
|
const getAll = (tableId: string | undefined) =>
|
||||||
|
makeRequest("get", `/tables/${postgresTable._id}/rows`)
|
||||||
|
|
||||||
|
test("Given than a table has no rows, get returns empty", async () => {
|
||||||
|
const res = await getAll(postgresTable._id)
|
||||||
|
|
||||||
|
expect(res.status).toBe(200)
|
||||||
|
|
||||||
|
expect(res.body.data).toHaveLength(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("Given than a table has multiple rows, get returns all of them", async () => {
|
||||||
|
const rowsCount = 6
|
||||||
|
const rows = await populateRows(rowsCount)
|
||||||
|
|
||||||
|
const res = await getAll(postgresTable._id)
|
||||||
|
|
||||||
|
expect(res.status).toBe(200)
|
||||||
|
|
||||||
|
expect(res.body.data).toHaveLength(rowsCount)
|
||||||
|
expect(res.body.data).toEqual(
|
||||||
|
expect.arrayContaining(
|
||||||
|
rows.map(r => expect.objectContaining(r.rowData))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("Given than multiple tables have multiple rows, get returns the requested ones", async () => {
|
||||||
|
await populateRows(2, (await config.createTable())._id)
|
||||||
|
const rowsCount = 6
|
||||||
|
await populateRows(rowsCount)
|
||||||
|
await populateRows(2, (await config.createTable())._id)
|
||||||
|
|
||||||
|
const res = await getAll(postgresTable._id)
|
||||||
|
|
||||||
|
expect(res.status).toBe(200)
|
||||||
|
|
||||||
|
expect(res.body.data).toHaveLength(rowsCount)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue