From f8a3c1260896c979db82d7662fd2e461c2c30da5 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 19 Jan 2023 16:46:05 +0000 Subject: [PATCH] Add get all rows tests --- .../src/integration-test/postgres.spec.ts | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/packages/server/src/integration-test/postgres.spec.ts b/packages/server/src/integration-test/postgres.spec.ts index f6b3ad67a5..f9ede157ef 100644 --- a/packages/server/src/integration-test/postgres.spec.ts +++ b/packages/server/src/integration-test/postgres.spec.ts @@ -449,15 +449,45 @@ describe("row api - postgres", () => { }) }) + describe("get all rows", () => { + const getAll = (tableId: string | undefined) => + makeRequest("get", `/api/${tableId}/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).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).toHaveLength(rowsCount) + expect(res.body).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, postgresTable._id) + await populateRows(2, (await config.createTable())._id) + const res = await getAll(postgresTable._id) + expect(res.status).toBe(200) + expect(res.body).toHaveLength(rowsCount) + }) + }) })