From 935aa521ff7fc1adfa7fe89a367ec085e1e88cdf Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 27 Aug 2024 17:02:19 +0200 Subject: [PATCH] Cleanup --- .../server/src/api/routes/tests/row.spec.ts | 141 ++++++++++-------- 1 file changed, 76 insertions(+), 65 deletions(-) diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index 3dabe45f8e..ca61918cad 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -2442,7 +2442,13 @@ describe.each([ let auxData: Row[] = [] + let flagCleanup: (() => void) | undefined + beforeAll(async () => { + flagCleanup = setCoreEnv({ + TENANT_FEATURE_FLAGS: `*:${FeatureFlag.ENRICHED_RELATIONSHIPS}`, + }) + const aux2Table = await config.api.table.save(saveTableRequest()) const aux2Data = await config.api.row.save(aux2Table._id!, {}) @@ -2564,6 +2570,10 @@ describe.each([ tableId = table._id! }) + afterAll(() => { + flagCleanup?.() + }) + const testScenarios: [string, (row: Row) => Promise | Row][] = [ ["get row", (row: Row) => config.api.row.get(tableId, row._id!)], [ @@ -2601,71 +2611,6 @@ describe.each([ it.each(testScenarios)( "can retrieve rows with populated relationships (via %s)", - async (__, retrieveDelegate) => { - const otherRows = _.sampleSize(auxData, 5) - await withCoreEnv( - { - TENANT_FEATURE_FLAGS: `*:${FeatureFlag.ENRICHED_RELATIONSHIPS}`, - }, - async () => { - const row = await config.api.row.save(tableId, { - 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, - name: otherRows[2].name, - age: otherRows[2].age, - id: otherRows[2].id, - }, - ], - relWithHalfSchema: [ - { - _id: otherRows[3]._id, - primaryDisplay: otherRows[3].name, - name: otherRows[3].name, - }, - ], - relWithIllegalSchema: [ - { - _id: otherRows[4]._id, - primaryDisplay: otherRows[4].name, - name: otherRows[4].name, - }, - ], - }) - ) - } - ) - } - ) - - it.each(testScenarios)( - "does not enrich relationships when not enabled (via %s)", async (__, retrieveDelegate) => { const otherRows = _.sampleSize(auxData, 5) @@ -2699,24 +2644,90 @@ describe.each([ { _id: otherRows[2]._id, primaryDisplay: otherRows[2].name, + name: otherRows[2].name, + age: otherRows[2].age, + id: otherRows[2].id, }, ], relWithHalfSchema: [ { _id: otherRows[3]._id, primaryDisplay: otherRows[3].name, + name: otherRows[3].name, }, ], relWithIllegalSchema: [ { _id: otherRows[4]._id, primaryDisplay: otherRows[4].name, + name: otherRows[4].name, }, ], }) ) } ) + + it.each(testScenarios)( + "does not enrich relationships when not enabled (via %s)", + async (__, retrieveDelegate) => { + await withCoreEnv( + { + TENANT_FEATURE_FLAGS: ``, + }, + async () => { + const otherRows = _.sampleSize(auxData, 5) + + const row = await config.api.row.save(tableId, { + 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", () => {