From 67f502579e1fc509df6578f01ec6d5cd56c13a39 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 25 Jul 2023 16:32:26 +0200 Subject: [PATCH] Test schema --- .../tests/core/utilities/jestUtils.ts | 13 +++++++++ .../server/src/api/routes/tests/row.spec.ts | 19 ++++-------- .../app/rows/search/tests/internal.spec.ts | 29 ++++++++++++++++++- 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/packages/backend-core/tests/core/utilities/jestUtils.ts b/packages/backend-core/tests/core/utilities/jestUtils.ts index d84eac548c..41b993cd17 100644 --- a/packages/backend-core/tests/core/utilities/jestUtils.ts +++ b/packages/backend-core/tests/core/utilities/jestUtils.ts @@ -1,3 +1,5 @@ +import { db } from "../../../src" + export function expectFunctionWasCalledTimesWith( jestFunction: any, times: number, @@ -7,3 +9,14 @@ export function expectFunctionWasCalledTimesWith( jestFunction.mock.calls.filter((call: any) => call[0] === argument).length ).toBe(times) } + +export const expectAnyInternalColsAttributes: { + [K in (typeof db.CONSTANT_INTERNAL_ROW_COLS)[number]]: any +} = { + tableId: expect.anything(), + type: expect.anything(), + _id: expect.anything(), + _rev: expect.anything(), + createdAt: expect.anything(), + updatedAt: expect.anything(), +} diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index 7ce9c12bac..6a5cfa77a2 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -17,7 +17,11 @@ import { SortType, SortOrder, } from "@budibase/types" -import { generator, structures } from "@budibase/backend-core/tests" +import { + expectAnyInternalColsAttributes, + generator, + structures, +} from "@budibase/backend-core/tests" describe("/rows", () => { let request = setup.getRequest() @@ -987,22 +991,11 @@ describe("/rows", () => { }) const response = await config.api.viewV2.search(createViewResponse.id) - const anyRowAttributes: { - [K in (typeof db.CONSTANT_INTERNAL_ROW_COLS)[number]]: any - } = { - tableId: expect.anything(), - type: expect.anything(), - _id: expect.anything(), - _rev: expect.anything(), - createdAt: expect.anything(), - updatedAt: expect.anything(), - } - expect(response.body.rows).toHaveLength(10) expect(response.body.rows).toEqual( expect.arrayContaining( rows.map(r => ({ - ...anyRowAttributes, + ...expectAnyInternalColsAttributes, name: r.name, })) ) diff --git a/packages/server/src/sdk/app/rows/search/tests/internal.spec.ts b/packages/server/src/sdk/app/rows/search/tests/internal.spec.ts index c91726b2d4..a58c368cea 100644 --- a/packages/server/src/sdk/app/rows/search/tests/internal.spec.ts +++ b/packages/server/src/sdk/app/rows/search/tests/internal.spec.ts @@ -2,7 +2,10 @@ import { FieldType, Row, Table } from "@budibase/types" import TestConfiguration from "../../../../../tests/utilities/TestConfiguration" import { SearchParams } from "../../search" import { search } from "../internal" -import { generator } from "@budibase/backend-core/tests" +import { + expectAnyInternalColsAttributes, + generator, +} from "@budibase/backend-core/tests" describe("internal", () => { const config = new TestConfiguration() @@ -78,5 +81,29 @@ describe("internal", () => { ) }) }) + + it("querying by fields will always return data attribute columns", async () => { + await config.doInContext(config.appId, async () => { + const tableId = config.table!._id! + + const searchParams: SearchParams = { + tableId, + query: {}, + fields: ["name", "age"], + } + const result = await search(searchParams) + + expect(result.rows).toHaveLength(10) + expect(result.rows).toEqual( + expect.arrayContaining( + rows.map(r => ({ + ...expectAnyInternalColsAttributes, + name: r.name, + age: r.age, + })) + ) + ) + }) + }) }) })