From 351ed643ce2c11290b2f4e5c272d7ca4b9b9e383 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 29 Aug 2024 12:30:16 +0200 Subject: [PATCH] Extra tests --- .../server/src/api/routes/tests/row.spec.ts | 98 +++++++++++++++---- 1 file changed, 77 insertions(+), 21 deletions(-) diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index 270323cfed..42ec0309ae 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -2434,6 +2434,7 @@ describe.each([ !isMSSQL && !isOracle && describe("relationships", () => { + let tableId: string let viewId: string let auxData: Row[] = [] @@ -2549,11 +2550,11 @@ describe.each([ }, }) ) - const tableId = table._id! + tableId = table._id! const view = await config.api.viewV2.create({ name: generator.guid(), tableId, - schema: { + schema: { title: { visible: true, }, @@ -2580,13 +2581,13 @@ describe.each([ relWithIllegalSchema: { visible: true, columns: { - name: { visible: true }, - address: { visible: true }, - unexisting: { visible: true }, - }, + name: { visible: true }, + address: { visible: true }, + unexisting: { visible: true }, }, }, - }) + }, + }) viewId = view.id }) @@ -2597,20 +2598,6 @@ describe.each([ const testScenarios: [string, (row: Row) => Promise | Row][] = [ ["get row", (row: Row) => config.api.row.get(viewId, row._id!)], - // [ - // "fetch", - // async (row: Row) => { - // const rows = await config.api.row.fetch(tableId) - // return rows.find(r => r._id === row._id) - // }, - // ], - // [ - // "search", - // async (row: Row) => { - // const { rows } = await config.api.row.search(tableId) - // return rows.find(r => r._id === row._id) - // }, - // ], [ "from view search", async (row: Row) => { @@ -2741,6 +2728,75 @@ describe.each([ ) } ) + + it.each([ + [ + "from table fetch", + async (row: Row) => { + const rows = await config.api.row.fetch(tableId) + return rows.find(r => r._id === row._id!) + }, + ], + [ + "from table search", + async (row: Row) => { + const { rows } = await config.api.row.search(tableId) + return rows.find(r => r._id === row._id!) + }, + ], + ])( + "does not enrich when fetching from the table (via %s)", + async (__, retrieveDelegate) => { + const otherRows = _.sampleSize(auxData, 5) + + const row = await config.api.row.save(viewId, { + title: generator.word(), + relWithNoSchema: [otherRows[0]], + relWithEmptySchema: [otherRows[1]], + relWithFullSchema: [otherRows[2]], + relWithHalfSchema: [otherRows[3]], + relWithIllegalSchema: [otherRows[4]], + }) + + const retrieved = await retrieveDelegate(row) + + expect(retrieved).toEqual( + expect.objectContaining({ + title: row.title, + relWithNoSchema: [ + { + _id: otherRows[0]._id, + primaryDisplay: otherRows[0].name, + }, + ], + relWithEmptySchema: [ + { + _id: otherRows[1]._id, + primaryDisplay: otherRows[1].name, + }, + ], + relWithFullSchema: [ + { + _id: otherRows[2]._id, + primaryDisplay: otherRows[2].name, + }, + ], + relWithHalfSchema: [ + { + _id: otherRows[3]._id, + primaryDisplay: otherRows[3].name, + }, + ], + relWithIllegalSchema: [ + { + _id: otherRows[4]._id, + primaryDisplay: otherRows[4].name, + }, + ], + }) + ) + } + ) }) describe("Formula fields", () => {