From bc090f5f9d69773135e2c082016bbd3a8262797a Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Thu, 15 Sep 2022 19:51:11 +0100 Subject: [PATCH] better tests and cleaner import for server --- .github/workflows/budibase_ci.yml | 3 +- packages/backend-core/yarn.lock | 5 + packages/server/specs/openapi.json | 221 +++++++++--------- packages/server/specs/openapi.yaml | 184 +++++++-------- packages/server/specs/resources/misc.js | 116 +++++++++ .../api/controllers/public/mapping/types.ts | 2 +- packages/server/src/api/routes/public/rows.ts | 83 +------ packages/server/src/definitions/openapi.ts | 105 ++++----- qa-core/package.json | 3 +- .../TestConfiguration/applications.ts | 4 +- .../public-api/TestConfiguration/rows.ts | 9 +- .../public-api/TestConfiguration/tables.ts | 4 +- .../public-api/TestConfiguration/users.ts | 4 +- .../public-api/fixtures/applications.ts | 2 +- .../src/config/public-api/fixtures/tables.ts | 10 +- .../src/config/public-api/fixtures/users.ts | 2 +- .../applications/applications.spec.ts | 9 +- .../src/tests/public-api/tables/rows.spec.ts | 25 +- .../tests/public-api/tables/tables.spec.ts | 8 +- .../src/tests/public-api/users/users.spec.ts | 10 +- qa-core/tsconfig.json | 1 + 21 files changed, 444 insertions(+), 366 deletions(-) diff --git a/.github/workflows/budibase_ci.yml b/.github/workflows/budibase_ci.yml index 23cdfba236..3715979922 100644 --- a/.github/workflows/budibase_ci.yml +++ b/.github/workflows/budibase_ci.yml @@ -60,7 +60,8 @@ jobs: # install: false # command: yarn test:e2e:ci - - run: | + - name: QA Core Integration Tests + run: | cd qa-core yarn yarn api:test:ci \ No newline at end of file diff --git a/packages/backend-core/yarn.lock b/packages/backend-core/yarn.lock index 22c17a9444..2e62aea734 100644 --- a/packages/backend-core/yarn.lock +++ b/packages/backend-core/yarn.lock @@ -1377,6 +1377,11 @@ bcrypt@5.0.1: "@mapbox/node-pre-gyp" "^1.0.0" node-addon-api "^3.1.0" +bcryptjs@2.4.3: + version "2.4.3" + resolved "https://registry.yarnpkg.com/bcryptjs/-/bcryptjs-2.4.3.tgz#9ab5627b93e60621ff7cdac5da9733027df1d0cb" + integrity sha512-V/Hy/X9Vt7f3BbPJEi8BdVFMByHi+jNXrYkW3huaybV/kQ0KJg0Y6PkEMbn+zeT+i+SiKZ/HMqJGIIt4LZDqNQ== + binary-extensions@^2.0.0: version "2.2.0" resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" diff --git a/packages/server/specs/openapi.json b/packages/server/specs/openapi.json index 97c0fa9551..f8539b9f7f 100644 --- a/packages/server/specs/openapi.json +++ b/packages/server/specs/openapi.json @@ -1659,6 +1659,117 @@ "data" ] }, + "rowSearch": { + "type": "object", + "properties": { + "query": { + "type": "object", + "properties": { + "allOr": { + "type": "boolean", + "description": "Specifies that a row should be returned if it satisfies any of the specified options, rather than requiring it to fulfill all the search parameters. This defaults to false, meaning AND logic will be used." + }, + "string": { + "type": "object", + "example": { + "columnName1": "value", + "columnName2": "value" + }, + "description": "A map of field name to the string to search for, this will look for rows that have a value starting with the string value.", + "additionalProperties": { + "type": "string", + "description": "The value to search for in the column." + } + }, + "fuzzy": { + "type": "object", + "description": "A fuzzy search, only supported by internal tables." + }, + "range": { + "type": "object", + "description": "Searches within a range, the format of this must be in the format of an object with a \"low\" and \"high\" property.", + "example": { + "columnName1": { + "low": 10, + "high": 20 + } + } + }, + "equal": { + "type": "object", + "description": "Searches for rows that have a column value that is exactly the value set." + }, + "notEqual": { + "type": "object", + "description": "Searches for any row which does not contain the specified column value." + }, + "empty": { + "type": "object", + "description": "Searches for rows which do not contain the specified column. The object should simply contain keys of the column names, these can map to any value.", + "example": { + "columnName1": "" + } + }, + "notEmpty": { + "type": "object", + "description": "Searches for rows which have the specified column." + }, + "oneOf": { + "type": "object", + "description": "Searches for rows which have a column value that is any of the specified values. The format of this must be columnName -> [value1, value2]." + } + } + }, + "paginate": { + "type": "boolean", + "description": "Enables pagination, by default this is disabled." + }, + "bookmark": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "integer" + } + ], + "description": "If retrieving another page, the bookmark from the previous request must be supplied." + }, + "limit": { + "type": "integer", + "description": "The maximum number of rows to return, useful when paginating, for internal tables this will be limited to 1000, for SQL tables it will be 5000." + }, + "sort": { + "type": "object", + "description": "A set of parameters describing the sort behaviour of the search.", + "properties": { + "order": { + "type": "string", + "enum": [ + "ascending", + "descending" + ], + "description": "The order of the sort, by default this is ascending." + }, + "column": { + "type": "string", + "description": "The name of the column by which the rows will be sorted." + }, + "type": { + "type": "string", + "enum": [ + "string", + "number" + ], + "description": "Defines whether the column should be treated as a string or as numbers when sorting." + } + } + } + }, + "required": [ + "query" + ] + }, "nameSearch": { "type": "object", "properties": { @@ -2129,115 +2240,7 @@ "content": { "application/json": { "schema": { - "type": "object", - "required": [ - "query" - ], - "properties": { - "query": { - "type": "object", - "properties": { - "allOr": { - "type": "boolean", - "description": "Specifies that a row should be returned if it satisfies any of the specified options, rather than requiring it to fulfill all the search parameters. This defaults to false, meaning AND logic will be used." - }, - "string": { - "type": "object", - "example": { - "columnName1": "value", - "columnName2": "value" - }, - "description": "A map of field name to the string to search for, this will look for rows that have a value starting with the string value.", - "additionalProperties": { - "type": "string", - "description": "The value to search for in the column." - } - }, - "fuzzy": { - "type": "object", - "description": "A fuzzy search, only supported by internal tables." - }, - "range": { - "type": "object", - "description": "Searches within a range, the format of this must be in the format of an object with a \"low\" and \"high\" property.", - "example": { - "columnName1": { - "low": 10, - "high": 20 - } - } - }, - "equal": { - "type": "object", - "description": "Searches for rows that have a column value that is exactly the value set." - }, - "notEqual": { - "type": "object", - "description": "Searches for any row which does not contain the specified column value." - }, - "empty": { - "type": "object", - "description": "Searches for rows which do not contain the specified column. The object should simply contain keys of the column names, these can map to any value.", - "example": { - "columnName1": "" - } - }, - "notEmpty": { - "type": "object", - "description": "Searches for rows which have the specified column." - }, - "oneOf": { - "type": "object", - "description": "Searches for rows which have a column value that is any of the specified values. The format of this must be columnName -> [value1, value2]." - } - } - }, - "paginate": { - "type": "boolean", - "description": "Enables pagination, by default this is disabled." - }, - "bookmark": { - "oneOf": [ - { - "type": "string" - }, - { - "type": "integer" - } - ], - "description": "If retrieving another page, the bookmark from the previous request must be supplied." - }, - "limit": { - "type": "integer", - "description": "The maximum number of rows to return, useful when paginating, for internal tables this will be limited to 1000, for SQL tables it will be 5000." - }, - "sort": { - "type": "object", - "description": "A set of parameters describing the sort behaviour of the search.", - "properties": { - "order": { - "type": "string", - "enum": [ - "ascending", - "descending" - ], - "description": "The order of the sort, by default this is ascending." - }, - "column": { - "type": "string", - "description": "The name of the column by which the rows will be sorted." - }, - "type": { - "type": "string", - "enum": [ - "string", - "number" - ], - "description": "Defines whether the column should be treated as a string or as numbers when sorting." - } - } - } - } + "$ref": "#/components/schemas/rowSearch" } } } diff --git a/packages/server/specs/openapi.yaml b/packages/server/specs/openapi.yaml index 3bcb893862..3cd29791af 100644 --- a/packages/server/specs/openapi.yaml +++ b/packages/server/specs/openapi.yaml @@ -1264,6 +1264,98 @@ components: - _id required: - data + rowSearch: + type: object + properties: + query: + type: object + properties: + allOr: + type: boolean + description: Specifies that a row should be returned if it satisfies any of the + specified options, rather than requiring it to fulfill all the + search parameters. This defaults to false, meaning AND logic + will be used. + string: + type: object + example: + columnName1: value + columnName2: value + description: A map of field name to the string to search for, this will look for + rows that have a value starting with the string value. + additionalProperties: + type: string + description: The value to search for in the column. + fuzzy: + type: object + description: A fuzzy search, only supported by internal tables. + range: + type: object + description: Searches within a range, the format of this must be in the format + of an object with a "low" and "high" property. + example: + columnName1: + low: 10 + high: 20 + equal: + type: object + description: Searches for rows that have a column value that is exactly the + value set. + notEqual: + type: object + description: Searches for any row which does not contain the specified column + value. + empty: + type: object + description: Searches for rows which do not contain the specified column. The + object should simply contain keys of the column names, these can + map to any value. + example: + columnName1: "" + notEmpty: + type: object + description: Searches for rows which have the specified column. + oneOf: + type: object + description: Searches for rows which have a column value that is any of the + specified values. The format of this must be columnName -> + [value1, value2]. + paginate: + type: boolean + description: Enables pagination, by default this is disabled. + bookmark: + oneOf: + - type: string + - type: integer + description: If retrieving another page, the bookmark from the previous request + must be supplied. + limit: + type: integer + description: The maximum number of rows to return, useful when paginating, for + internal tables this will be limited to 1000, for SQL tables it will + be 5000. + sort: + type: object + description: A set of parameters describing the sort behaviour of the search. + properties: + order: + type: string + enum: + - ascending + - descending + description: The order of the sort, by default this is ascending. + column: + type: string + description: The name of the column by which the rows will be sorted. + type: + type: string + enum: + - string + - number + description: Defines whether the column should be treated as a string or as + numbers when sorting. + required: + - query nameSearch: type: object properties: @@ -1544,97 +1636,7 @@ paths: content: application/json: schema: - type: object - required: - - query - properties: - query: - type: object - properties: - allOr: - type: boolean - description: Specifies that a row should be returned if it satisfies any of the - specified options, rather than requiring it to fulfill - all the search parameters. This defaults to false, - meaning AND logic will be used. - string: - type: object - example: - columnName1: value - columnName2: value - description: A map of field name to the string to search for, this will look for - rows that have a value starting with the string value. - additionalProperties: - type: string - description: The value to search for in the column. - fuzzy: - type: object - description: A fuzzy search, only supported by internal tables. - range: - type: object - description: Searches within a range, the format of this must be in the format - of an object with a "low" and "high" property. - example: - columnName1: - low: 10 - high: 20 - equal: - type: object - description: Searches for rows that have a column value that is exactly the - value set. - notEqual: - type: object - description: Searches for any row which does not contain the specified column - value. - empty: - type: object - description: Searches for rows which do not contain the specified column. The - object should simply contain keys of the column names, - these can map to any value. - example: - columnName1: "" - notEmpty: - type: object - description: Searches for rows which have the specified column. - oneOf: - type: object - description: Searches for rows which have a column value that is any of the - specified values. The format of this must be columnName - -> [value1, value2]. - paginate: - type: boolean - description: Enables pagination, by default this is disabled. - bookmark: - oneOf: - - type: string - - type: integer - description: If retrieving another page, the bookmark from the previous request - must be supplied. - limit: - type: integer - description: The maximum number of rows to return, useful when paginating, for - internal tables this will be limited to 1000, for SQL tables - it will be 5000. - sort: - type: object - description: A set of parameters describing the sort behaviour of the search. - properties: - order: - type: string - enum: - - ascending - - descending - description: The order of the sort, by default this is ascending. - column: - type: string - description: The name of the column by which the rows will be sorted. - type: - type: string - enum: - - string - - number - description: Defines whether the column should be treated as a string or as - numbers when sorting. + $ref: "#/components/schemas/rowSearch" responses: "200": description: The response will contain an array of rows that match the search diff --git a/packages/server/specs/resources/misc.js b/packages/server/specs/resources/misc.js index bf92680ca8..32a81da9ec 100644 --- a/packages/server/specs/resources/misc.js +++ b/packages/server/specs/resources/misc.js @@ -2,6 +2,122 @@ const { object } = require("./utils") const Resource = require("./utils/Resource") module.exports = new Resource().setSchemas({ + rowSearch: object( + { + query: { + type: "object", + properties: { + allOr: { + type: "boolean", + description: + "Specifies that a row should be returned if it satisfies any of the specified options, rather than requiring it to fulfill all the search parameters. This defaults to false, meaning AND logic will be used.", + }, + string: { + type: "object", + example: { + columnName1: "value", + columnName2: "value", + }, + description: + "A map of field name to the string to search for, this will look for rows that have a value starting with the string value.", + additionalProperties: { + type: "string", + description: "The value to search for in the column.", + }, + }, + fuzzy: { + type: "object", + description: "A fuzzy search, only supported by internal tables.", + }, + range: { + type: "object", + description: + 'Searches within a range, the format of this must be in the format of an object with a "low" and "high" property.', + example: { + columnName1: { + low: 10, + high: 20, + }, + }, + }, + equal: { + type: "object", + description: + "Searches for rows that have a column value that is exactly the value set.", + }, + notEqual: { + type: "object", + description: + "Searches for any row which does not contain the specified column value.", + }, + empty: { + type: "object", + description: + "Searches for rows which do not contain the specified column. The object should simply contain keys of the column names, these can map to any value.", + example: { + columnName1: "", + }, + }, + notEmpty: { + type: "object", + description: "Searches for rows which have the specified column.", + }, + oneOf: { + type: "object", + description: + "Searches for rows which have a column value that is any of the specified values. The format of this must be columnName -> [value1, value2].", + }, + }, + }, + paginate: { + type: "boolean", + description: "Enables pagination, by default this is disabled.", + }, + bookmark: { + oneOf: [ + { + type: "string", + }, + { + type: "integer", + }, + ], + description: + "If retrieving another page, the bookmark from the previous request must be supplied.", + }, + limit: { + type: "integer", + description: + "The maximum number of rows to return, useful when paginating, for internal tables this will be limited to 1000, for SQL tables it will be 5000.", + }, + sort: { + type: "object", + description: + "A set of parameters describing the sort behaviour of the search.", + properties: { + order: { + type: "string", + enum: ["ascending", "descending"], + description: "The order of the sort, by default this is ascending.", + }, + column: { + type: "string", + description: + "The name of the column by which the rows will be sorted.", + }, + type: { + type: "string", + enum: ["string", "number"], + description: + "Defines whether the column should be treated as a string or as numbers when sorting.", + }, + }, + }, + }, + { + required: ["query"], + } + ), nameSearch: object({ name: { type: "string", diff --git a/packages/server/src/api/controllers/public/mapping/types.ts b/packages/server/src/api/controllers/public/mapping/types.ts index 5d161ec17a..e3c8719d87 100644 --- a/packages/server/src/api/controllers/public/mapping/types.ts +++ b/packages/server/src/api/controllers/public/mapping/types.ts @@ -18,4 +18,4 @@ export type CreateUserParams = components["schemas"]["user"] export type SearchInputParams = | components["schemas"]["nameSearch"] - | components["schemas"]["querySearch"] + | components["schemas"]["rowSearch"] diff --git a/packages/server/src/api/routes/public/rows.ts b/packages/server/src/api/routes/public/rows.ts index 7c9e4f7af7..80da073e3e 100644 --- a/packages/server/src/api/routes/public/rows.ts +++ b/packages/server/src/api/routes/public/rows.ts @@ -143,88 +143,7 @@ read.push(new Endpoint("get", "/tables/:tableId/rows/:rowId", controller.read)) * content: * application/json: * schema: - * type: object - * required: - * - query - * properties: - * query: - * type: object - * properties: - * allOr: - * type: boolean - * description: Specifies that a row should be returned if it satisfies - * any of the specified options, rather than requiring it to fulfill all - * the search parameters. This defaults to false, meaning AND logic will be used. - * string: - * type: object - * example: - * columnName1: value - * columnName2: value - * description: A map of field name to the string to search for, - * this will look for rows that have a value starting with the - * string value. - * additionalProperties: - * type: string - * description: The value to search for in the column. - * fuzzy: - * type: object - * description: A fuzzy search, only supported by internal tables. - * range: - * type: object - * description: Searches within a range, the format of this must be - * in the format of an object with a "low" and "high" property. - * example: - * columnName1: { low: 10, high: 20 } - * equal: - * type: object - * description: Searches for rows that have a column value that is - * exactly the value set. - * notEqual: - * type: object - * description: Searches for any row which does not contain the specified - * column value. - * empty: - * type: object - * description: Searches for rows which do not contain the specified column. - * The object should simply contain keys of the column names, these - * can map to any value. - * example: - * columnName1: "" - * notEmpty: - * type: object - * description: Searches for rows which have the specified column. - * oneOf: - * type: object - * description: Searches for rows which have a column value that is any - * of the specified values. The format of this must be columnName -> [value1, value2]. - * paginate: - * type: boolean - * description: Enables pagination, by default this is disabled. - * bookmark: - * oneOf: - * - type: string - * - type: integer - * description: If retrieving another page, the bookmark from the previous request must be supplied. - * limit: - * type: integer - * description: The maximum number of rows to return, useful when paginating, for internal tables this - * will be limited to 1000, for SQL tables it will be 5000. - * sort: - * type: object - * description: A set of parameters describing the sort behaviour of the search. - * properties: - * order: - * type: string - * enum: [ascending, descending] - * description: The order of the sort, by default this is ascending. - * column: - * type: string - * description: The name of the column by which the rows will be sorted. - * type: - * type: string - * enum: [string, number] - * description: Defines whether the column should be treated as a string - * or as numbers when sorting. + * $ref: '#/components/schemas/rowSearch' * responses: * 200: * description: The response will contain an array of rows that match the search parameters. diff --git a/packages/server/src/definitions/openapi.ts b/packages/server/src/definitions/openapi.ts index 486901acad..a4bd0c1e3e 100644 --- a/packages/server/src/definitions/openapi.ts +++ b/packages/server/src/definitions/openapi.ts @@ -278,58 +278,7 @@ export interface paths { }; requestBody: { content: { - "application/json": { - query: { - /** @description Specifies that a row should be returned if it satisfies any of the specified options, rather than requiring it to fulfill all the search parameters. This defaults to false, meaning AND logic will be used. */ - allOr?: boolean; - /** - * @description A map of field name to the string to search for, this will look for rows that have a value starting with the string value. - * @example [object Object] - */ - string?: { [key: string]: string }; - /** @description A fuzzy search, only supported by internal tables. */ - fuzzy?: { [key: string]: unknown }; - /** - * @description Searches within a range, the format of this must be in the format of an object with a "low" and "high" property. - * @example [object Object] - */ - range?: { [key: string]: unknown }; - /** @description Searches for rows that have a column value that is exactly the value set. */ - equal?: { [key: string]: unknown }; - /** @description Searches for any row which does not contain the specified column value. */ - notEqual?: { [key: string]: unknown }; - /** - * @description Searches for rows which do not contain the specified column. The object should simply contain keys of the column names, these can map to any value. - * @example [object Object] - */ - empty?: { [key: string]: unknown }; - /** @description Searches for rows which have the specified column. */ - notEmpty?: { [key: string]: unknown }; - /** @description Searches for rows which have a column value that is any of the specified values. The format of this must be columnName -> [value1, value2]. */ - oneOf?: { [key: string]: unknown }; - }; - /** @description Enables pagination, by default this is disabled. */ - paginate?: boolean; - /** @description If retrieving another page, the bookmark from the previous request must be supplied. */ - bookmark?: string | number; - /** @description The maximum number of rows to return, useful when paginating, for internal tables this will be limited to 1000, for SQL tables it will be 5000. */ - limit?: number; - /** @description A set of parameters describing the sort behaviour of the search. */ - sort?: { - /** - * @description The order of the sort, by default this is ascending. - * @enum {string} - */ - order?: "ascending" | "descending"; - /** @description The name of the column by which the rows will be sorted. */ - column?: string; - /** - * @description Defines whether the column should be treated as a string or as numbers when sorting. - * @enum {string} - */ - type?: "string" | "number"; - }; - }; + "application/json": components["schemas"]["rowSearch"]; }; }; }; @@ -1105,6 +1054,58 @@ export interface components { _id: string; }[]; }; + rowSearch: { + query: { + /** @description Specifies that a row should be returned if it satisfies any of the specified options, rather than requiring it to fulfill all the search parameters. This defaults to false, meaning AND logic will be used. */ + allOr?: boolean; + /** + * @description A map of field name to the string to search for, this will look for rows that have a value starting with the string value. + * @example [object Object] + */ + string?: { [key: string]: string }; + /** @description A fuzzy search, only supported by internal tables. */ + fuzzy?: { [key: string]: unknown }; + /** + * @description Searches within a range, the format of this must be in the format of an object with a "low" and "high" property. + * @example [object Object] + */ + range?: { [key: string]: unknown }; + /** @description Searches for rows that have a column value that is exactly the value set. */ + equal?: { [key: string]: unknown }; + /** @description Searches for any row which does not contain the specified column value. */ + notEqual?: { [key: string]: unknown }; + /** + * @description Searches for rows which do not contain the specified column. The object should simply contain keys of the column names, these can map to any value. + * @example [object Object] + */ + empty?: { [key: string]: unknown }; + /** @description Searches for rows which have the specified column. */ + notEmpty?: { [key: string]: unknown }; + /** @description Searches for rows which have a column value that is any of the specified values. The format of this must be columnName -> [value1, value2]. */ + oneOf?: { [key: string]: unknown }; + }; + /** @description Enables pagination, by default this is disabled. */ + paginate?: boolean; + /** @description If retrieving another page, the bookmark from the previous request must be supplied. */ + bookmark?: string | number; + /** @description The maximum number of rows to return, useful when paginating, for internal tables this will be limited to 1000, for SQL tables it will be 5000. */ + limit?: number; + /** @description A set of parameters describing the sort behaviour of the search. */ + sort?: { + /** + * @description The order of the sort, by default this is ascending. + * @enum {string} + */ + order?: "ascending" | "descending"; + /** @description The name of the column by which the rows will be sorted. */ + column?: string; + /** + * @description Defines whether the column should be treated as a string or as numbers when sorting. + * @enum {string} + */ + type?: "string" | "number"; + }; + }; nameSearch: { /** @description The name to be used when searching - this will be used in a case insensitive starts with match. */ name: string; diff --git a/qa-core/package.json b/qa-core/package.json index 2103f1670e..f82849c92e 100644 --- a/qa-core/package.json +++ b/qa-core/package.json @@ -21,7 +21,8 @@ "preset": "ts-jest", "testEnvironment": "node", "moduleNameMapper": { - "@budibase/types": "/../packages/types/src" + "@budibase/types": "/../packages/types/src", + "@budibase/server": "/../packages/server/src" }, "setupFiles": [ "./scripts/jestSetup.js" diff --git a/qa-core/src/config/public-api/TestConfiguration/applications.ts b/qa-core/src/config/public-api/TestConfiguration/applications.ts index 6232c14c28..79de8f570d 100644 --- a/qa-core/src/config/public-api/TestConfiguration/applications.ts +++ b/qa-core/src/config/public-api/TestConfiguration/applications.ts @@ -3,7 +3,7 @@ import { Application, SearchInputParams, CreateApplicationParams, -} from "../../../../../packages/server/src/api/controllers/public/mapping/types" +} from "@budibase/server/api/controllers/public/mapping/types" import { Response } from "node-fetch" import generateApp from "../fixtures/applications" @@ -32,7 +32,7 @@ export default class AppApi { return [response, json.data] } - async search(body: SearchInputParams): Promise<[Response, Application]> { + async search(body: SearchInputParams): Promise<[Response, [Application]]> { const response = await this.api.post(`/applications/search`, { body }) const json = await response.json() return [response, json.data] diff --git a/qa-core/src/config/public-api/TestConfiguration/rows.ts b/qa-core/src/config/public-api/TestConfiguration/rows.ts index 8a85e2cd77..c3689de5d8 100644 --- a/qa-core/src/config/public-api/TestConfiguration/rows.ts +++ b/qa-core/src/config/public-api/TestConfiguration/rows.ts @@ -3,8 +3,9 @@ import { CreateRowParams, Row, SearchInputParams, -} from "../../../../../packages/server/src/api/controllers/public/mapping/types" +} from "@budibase/server/api/controllers/public/mapping/types" import { HeadersInit, Response } from "node-fetch" +import { generateRow } from "../fixtures/tables" export default class RowApi { api: PublicAPIClient @@ -15,6 +16,10 @@ export default class RowApi { this.api = apiClient } + async seed(tableId: string) { + return this.create(generateRow({ tableId })) + } + async create(body: CreateRowParams): Promise<[Response, Row]> { const response = await this.api.post(`/tables/${this.tableId}/rows`, { body, @@ -29,7 +34,7 @@ export default class RowApi { return [response, json.data] } - async search(body: SearchInputParams): Promise<[Response, Row]> { + async search(body: SearchInputParams): Promise<[Response, [Row]]> { const response = await this.api.post( `/tables/${this.tableId}/rows/search`, { body } diff --git a/qa-core/src/config/public-api/TestConfiguration/tables.ts b/qa-core/src/config/public-api/TestConfiguration/tables.ts index 847b4d00cc..9a1c9db019 100644 --- a/qa-core/src/config/public-api/TestConfiguration/tables.ts +++ b/qa-core/src/config/public-api/TestConfiguration/tables.ts @@ -3,7 +3,7 @@ import { Table, SearchInputParams, CreateTableParams, -} from "../../../../../packages/server/src/api/controllers/public/mapping/types" +} from "@budibase/server/api/controllers/public/mapping/types" import { HeadersInit, Response } from "node-fetch" import { generateTable } from "../fixtures/tables" @@ -33,7 +33,7 @@ export default class TableApi { return [response, json.data] } - async search(body: SearchInputParams): Promise<[Response, Table]> { + async search(body: SearchInputParams): Promise<[Response, [Table]]> { const response = await this.api.post(`/tables/search`, { body }) const json = await response.json() return [response, json.data] diff --git a/qa-core/src/config/public-api/TestConfiguration/users.ts b/qa-core/src/config/public-api/TestConfiguration/users.ts index 34c5f57a1a..c332777aed 100644 --- a/qa-core/src/config/public-api/TestConfiguration/users.ts +++ b/qa-core/src/config/public-api/TestConfiguration/users.ts @@ -3,7 +3,7 @@ import { CreateUserParams, SearchInputParams, User, -} from "../../../../../packages/server/src/api/controllers/public/mapping/types" +} from "@budibase/server/api/controllers/public/mapping/types" import { Response } from "node-fetch" import generateUser from "../fixtures/users" @@ -30,7 +30,7 @@ export default class UserApi { return [response, json.data] } - async search(body: SearchInputParams): Promise<[Response, User]> { + async search(body: SearchInputParams): Promise<[Response, [User]]> { const response = await this.api.post(`/users/search`, { body }) const json = await response.json() return [response, json.data] diff --git a/qa-core/src/config/public-api/fixtures/applications.ts b/qa-core/src/config/public-api/fixtures/applications.ts index 731c240c04..3b58faa95f 100644 --- a/qa-core/src/config/public-api/fixtures/applications.ts +++ b/qa-core/src/config/public-api/fixtures/applications.ts @@ -2,7 +2,7 @@ import generator from "../TestConfiguration/generator" import { Application, CreateApplicationParams, -} from "../../../../../packages/server/src/api/controllers/public/mapping/types" +} from "@budibase/server/api/controllers/public/mapping/types" const generate = ( overrides: Partial = {} diff --git a/qa-core/src/config/public-api/fixtures/tables.ts b/qa-core/src/config/public-api/fixtures/tables.ts index 8d47076e5c..cf76855439 100644 --- a/qa-core/src/config/public-api/fixtures/tables.ts +++ b/qa-core/src/config/public-api/fixtures/tables.ts @@ -3,14 +3,14 @@ import { CreateTableParams, Row, Table, -} from "../../../../../packages/server/src/api/controllers/public/mapping/types" +} from "@budibase/server/api/controllers/public/mapping/types" import generator from "../TestConfiguration/generator" export const generateTable = ( overrides: Partial = {} ): CreateTableParams => ({ name: generator.word(), - primaryDisplay: "sasa", + primaryDisplay: "testColumn", schema: { "Auto ID": { autocolumn: true, @@ -30,8 +30,8 @@ export const generateTable = ( tableId: "ta_users", type: "link", }, - sasa: { - name: "sasa", + testColumn: { + name: "testColumn", type: "string", }, "Updated At": { @@ -54,7 +54,7 @@ export const generateTable = ( export const generateRow = (overrides: Partial = {}): CreateRowParams => ({ type: "row", tableId: "seed_table", - sasa: generator.word(), + testColumn: generator.word(), relationship: [generator.string({ length: 32, alpha: true, numeric: true })], ...overrides, }) diff --git a/qa-core/src/config/public-api/fixtures/users.ts b/qa-core/src/config/public-api/fixtures/users.ts index aaca5f2480..4aea5333bf 100644 --- a/qa-core/src/config/public-api/fixtures/users.ts +++ b/qa-core/src/config/public-api/fixtures/users.ts @@ -1,7 +1,7 @@ import { CreateUserParams, User, -} from "../../../../../packages/server/src/api/controllers/public/mapping/types" +} from "@budibase/server/api/controllers/public/mapping/types" import generator from "../TestConfiguration/generator" const generate = (overrides: Partial = {}): CreateUserParams => ({ diff --git a/qa-core/src/tests/public-api/applications/applications.spec.ts b/qa-core/src/tests/public-api/applications/applications.spec.ts index 59a24861af..05eaca6177 100644 --- a/qa-core/src/tests/public-api/applications/applications.spec.ts +++ b/qa-core/src/tests/public-api/applications/applications.spec.ts @@ -1,7 +1,7 @@ import TestConfiguration from "../../../config/public-api/TestConfiguration" import PublicAPIClient from "../../../config/public-api/TestConfiguration/PublicAPIClient" import generateApp from "../../../config/public-api/fixtures/applications" -import { Application } from "../../../../../packages/server/src/api/controllers/public/mapping/types" +import { Application } from "@budibase/server/api/controllers/public/mapping/types" describe("Public API - /applications endpoints", () => { const api = new PublicAPIClient() @@ -20,18 +20,21 @@ describe("Public API - /applications endpoints", () => { it("POST - Create an application", async () => { const [response, app] = await config.applications.create(generateApp()) expect(response).toHaveStatusCode(200) + expect(app._id).toBeDefined() }) it("POST - Search applications", async () => { - const [response, app] = await config.applications.search({ + const [response, apps] = await config.applications.search({ name: config.context.name, }) expect(response).toHaveStatusCode(200) + expect(apps[0]).toEqual(config.context) }) it("GET - Retrieve an application", async () => { const [response, app] = await config.applications.read(config.context._id) expect(response).toHaveStatusCode(200) + expect(app).toEqual(config.context) }) it("PUT - update an application", async () => { @@ -41,5 +44,7 @@ describe("Public API - /applications endpoints", () => { config.context ) expect(response).toHaveStatusCode(200) + expect(app.updatedAt).not.toEqual(config.context.updatedAt) + expect(app.name).toEqual(config.context.name) }) }) diff --git a/qa-core/src/tests/public-api/tables/rows.spec.ts b/qa-core/src/tests/public-api/tables/rows.spec.ts index f34c4cde29..91df85e65c 100644 --- a/qa-core/src/tests/public-api/tables/rows.spec.ts +++ b/qa-core/src/tests/public-api/tables/rows.spec.ts @@ -1,4 +1,4 @@ -import { Row } from "../../../../../packages/server/src/api/controllers/public/mapping/types" +import { Row } from "@budibase/server/api/controllers/public/mapping/types" import { generateRow } from "../../../config/public-api/fixtures/tables" import TestConfiguration from "../../../config/public-api/TestConfiguration" import PublicAPIClient from "../../../config/public-api/TestConfiguration/PublicAPIClient" @@ -10,15 +10,15 @@ describe("Public API - /rows endpoints", () => { beforeAll(async () => { await config.beforeAll() - const [appResp, app] = await config.applications.seed() + const [aResp, app] = await config.applications.seed() config.tables.api.appId = app._id config.rows.api.appId = app._id - const [tableResp, table] = await config.tables.seed() + const [tResp, table] = await config.tables.seed() config.rows.tableId = table._id - const [response, row] = await config.rows.create(generateRow()) + const [rResp, row] = await config.rows.seed(table._id) config.context = row }) @@ -29,26 +29,37 @@ describe("Public API - /rows endpoints", () => { it("POST - Create a row", async () => { const [response, row] = await config.rows.create(generateRow()) expect(response).toHaveStatusCode(200) + expect(row._id).toBeDefined() }) it("POST - Search rows", async () => { - const [response, row] = await config.rows.search({ - name: config.context.name as string, + const [response, rows] = await config.rows.search({ + query: { + string: { + testColumn: config.context.testColumn as string, + }, + }, }) expect(response).toHaveStatusCode(200) + expect(rows[0]._id).toEqual(config.context._id) + expect(rows[0].tableId).toEqual(config.context.tableId) + expect(rows[0].testColumn).toEqual(config.context.testColumn) }) it("GET - Retrieve a row", async () => { const [response, row] = await config.rows.read(config.context._id) expect(response).toHaveStatusCode(200) + expect(row._id).toEqual(config.context._id) + expect(row.tableId).toEqual(config.context.tableId) }) it("PUT - update a row", async () => { - config.context.name = "UpdatedName" + config.context.testColumn = "UpdatedName" const [response, row] = await config.rows.update( config.context._id, config.context ) expect(response).toHaveStatusCode(200) + expect(row.testColumn).toEqual(config.context.testColumn) }) }) diff --git a/qa-core/src/tests/public-api/tables/tables.spec.ts b/qa-core/src/tests/public-api/tables/tables.spec.ts index c2f50d3e8e..de1ce142ce 100644 --- a/qa-core/src/tests/public-api/tables/tables.spec.ts +++ b/qa-core/src/tests/public-api/tables/tables.spec.ts @@ -1,4 +1,4 @@ -import { Table } from "../../../../../packages/server/src/api/controllers/public/mapping/types" +import { Table } from "@budibase/server/api/controllers/public/mapping/types" import { generateTable } from "../../../config/public-api/fixtures/tables" import TestConfiguration from "../../../config/public-api/TestConfiguration" import PublicAPIClient from "../../../config/public-api/TestConfiguration/PublicAPIClient" @@ -23,18 +23,21 @@ describe("Public API - /tables endpoints", () => { it("POST - Create a table", async () => { const [response, table] = await config.tables.create(generateTable()) expect(response).toHaveStatusCode(200) + expect(table._id).toBeDefined() }) it("POST - Search tables", async () => { - const [response, table] = await config.tables.search({ + const [response, tables] = await config.tables.search({ name: config.context.name, }) expect(response).toHaveStatusCode(200) + expect(tables[0]).toEqual(config.context) }) it("GET - Retrieve a table", async () => { const [response, table] = await config.tables.read(config.context._id) expect(response).toHaveStatusCode(200) + expect(table).toEqual(config.context) }) it("PUT - update a table", async () => { @@ -44,5 +47,6 @@ describe("Public API - /tables endpoints", () => { config.context ) expect(response).toHaveStatusCode(200) + expect(table).toEqual(config.context) }) }) diff --git a/qa-core/src/tests/public-api/users/users.spec.ts b/qa-core/src/tests/public-api/users/users.spec.ts index b981deb786..5e68c77c50 100644 --- a/qa-core/src/tests/public-api/users/users.spec.ts +++ b/qa-core/src/tests/public-api/users/users.spec.ts @@ -1,7 +1,7 @@ import TestConfiguration from "../../../config/public-api/TestConfiguration" import PublicAPIClient from "../../../config/public-api/TestConfiguration/PublicAPIClient" import generateUser from "../../../config/public-api/fixtures/users" -import { User } from "../../../../../packages/server/src/api/controllers/public/mapping/types" +import { User } from "@budibase/server/api/controllers/public/mapping/types" describe("Public API - /users endpoints", () => { const api = new PublicAPIClient() @@ -9,7 +9,7 @@ describe("Public API - /users endpoints", () => { beforeAll(async () => { await config.beforeAll() - const [response, user] = await config.users.seed() + const [_, user] = await config.users.seed() config.context = user }) @@ -20,18 +20,21 @@ describe("Public API - /users endpoints", () => { it("POST - Create a user", async () => { const [response, user] = await config.users.create(generateUser()) expect(response).toHaveStatusCode(200) + expect(user._id).toBeDefined() }) it("POST - Search users", async () => { - const [response, user] = await config.users.search({ + const [response, users] = await config.users.search({ name: config.context.email, }) expect(response).toHaveStatusCode(200) + expect(users[0]).toEqual(config.context) }) it("GET - Retrieve a user", async () => { const [response, user] = await config.users.read(config.context._id) expect(response).toHaveStatusCode(200) + expect(user).toEqual(config.context) }) it("PUT - update a user", async () => { @@ -41,5 +44,6 @@ describe("Public API - /users endpoints", () => { config.context ) expect(response).toHaveStatusCode(200) + expect(user).toEqual(config.context) }) }) diff --git a/qa-core/tsconfig.json b/qa-core/tsconfig.json index 0fa56727b8..b5f3f25fdd 100644 --- a/qa-core/tsconfig.json +++ b/qa-core/tsconfig.json @@ -14,6 +14,7 @@ "skipLibCheck": true, "paths": { "@budibase/types": ["../packages/types/src"], + "@budibase/server/*": ["../packages/server/src/*"], } }, "ts-node": {