From f4760d703b83cc4327a04c0bb897a8a06b0ee50e Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Thu, 15 Sep 2022 09:48:44 +0100 Subject: [PATCH] better generation, and letting tests run in isolation --- .../public-api/TestConfiguration/rows.ts | 14 ++----------- .../public-api/TestConfiguration/tables.ts | 21 +++---------------- .../public-api/TestConfiguration/users.ts | 5 ++++- .../public-api/fixtures/applications.ts | 9 ++++++-- .../src/config/public-api/fixtures/tables.ts | 16 ++++++++------ .../src/config/public-api/fixtures/users.ts | 7 +++++-- .../applications/applications.spec.ts | 3 ++- .../src/tests/public-api/tables/rows.spec.ts | 10 +++++---- .../tests/public-api/tables/tables.spec.ts | 8 ++++--- .../src/tests/public-api/users/users.spec.ts | 3 ++- 10 files changed, 46 insertions(+), 50 deletions(-) diff --git a/qa-core/src/config/public-api/TestConfiguration/rows.ts b/qa-core/src/config/public-api/TestConfiguration/rows.ts index 4e39e4ec9e..8a85e2cd77 100644 --- a/qa-core/src/config/public-api/TestConfiguration/rows.ts +++ b/qa-core/src/config/public-api/TestConfiguration/rows.ts @@ -15,25 +15,16 @@ export default class RowApi { this.api = apiClient } - set appId(appId: string) { - this.headers = { - "x-budibase-app-id": appId, - } - } - async create(body: CreateRowParams): Promise<[Response, Row]> { const response = await this.api.post(`/tables/${this.tableId}/rows`, { body, - headers: this.headers, }) const json = await response.json() return [response, json.data] } async read(id: string): Promise<[Response, Row]> { - const response = await this.api.get(`/tables/${this.tableId}/rows/${id}`, { - headers: this.headers, - }) + const response = await this.api.get(`/tables/${this.tableId}/rows/${id}`) const json = await response.json() return [response, json.data] } @@ -41,7 +32,7 @@ export default class RowApi { async search(body: SearchInputParams): Promise<[Response, Row]> { const response = await this.api.post( `/tables/${this.tableId}/rows/search`, - { body, headers: this.headers } + { body } ) const json = await response.json() return [response, json.data] @@ -50,7 +41,6 @@ export default class RowApi { async update(id: string, body: Row): Promise<[Response, Row]> { const response = await this.api.put(`/tables/${this.tableId}/rows/${id}`, { body, - headers: this.headers, }) const json = await response.json() return [response, json.data] diff --git a/qa-core/src/config/public-api/TestConfiguration/tables.ts b/qa-core/src/config/public-api/TestConfiguration/tables.ts index c0b7e088e1..847b4d00cc 100644 --- a/qa-core/src/config/public-api/TestConfiguration/tables.ts +++ b/qa-core/src/config/public-api/TestConfiguration/tables.ts @@ -19,43 +19,28 @@ export default class TableApi { return this.create(generateTable()) } - set appId(appId: string) { - this.headers = { - "x-budibase-app-id": appId, - } - } - async create(body: CreateTableParams): Promise<[Response, Table]> { const response = await this.api.post(`/tables`, { body, - headers: this.headers, }) const json = await response.json() return [response, json.data] } async read(id: string): Promise<[Response, Table]> { - const response = await this.api.get(`/tables/${id}`, { - headers: this.headers, - }) + const response = await this.api.get(`/tables/${id}`) const json = await response.json() return [response, json.data] } async search(body: SearchInputParams): Promise<[Response, Table]> { - const response = await this.api.post(`/tables/search`, { - body, - headers: this.headers, - }) + const response = await this.api.post(`/tables/search`, { body }) const json = await response.json() return [response, json.data] } async update(id: string, body: Table): Promise<[Response, Table]> { - const response = await this.api.put(`/tables/${id}`, { - body, - headers: this.headers, - }) + const response = await this.api.put(`/tables/${id}`, { 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 79217620aa..34c5f57a1a 100644 --- a/qa-core/src/config/public-api/TestConfiguration/users.ts +++ b/qa-core/src/config/public-api/TestConfiguration/users.ts @@ -5,6 +5,7 @@ import { User, } from "../../../../../packages/server/src/api/controllers/public/mapping/types" import { Response } from "node-fetch" +import generateUser from "../fixtures/users" export default class UserApi { api: PublicAPIClient @@ -13,7 +14,9 @@ export default class UserApi { this.api = apiClient } - async seed() {} + async seed() { + return this.create(generateUser()) + } async create(body: CreateUserParams): Promise<[Response, User]> { const response = await this.api.post(`/users`, { body }) diff --git a/qa-core/src/config/public-api/fixtures/applications.ts b/qa-core/src/config/public-api/fixtures/applications.ts index 25456f4c4b..731c240c04 100644 --- a/qa-core/src/config/public-api/fixtures/applications.ts +++ b/qa-core/src/config/public-api/fixtures/applications.ts @@ -1,7 +1,12 @@ import generator from "../TestConfiguration/generator" -import { CreateApplicationParams } from "../../../../../packages/server/src/api/controllers/public/mapping/types" +import { + Application, + CreateApplicationParams, +} from "../../../../../packages/server/src/api/controllers/public/mapping/types" -const generate = (overrides = {}): CreateApplicationParams => ({ +const generate = ( + overrides: Partial = {} +): CreateApplicationParams => ({ name: generator.word(), url: `/${generator.word()}`, ...overrides, diff --git a/qa-core/src/config/public-api/fixtures/tables.ts b/qa-core/src/config/public-api/fixtures/tables.ts index bbf93322c3..8d47076e5c 100644 --- a/qa-core/src/config/public-api/fixtures/tables.ts +++ b/qa-core/src/config/public-api/fixtures/tables.ts @@ -1,10 +1,14 @@ import { CreateRowParams, CreateTableParams, + Row, + Table, } from "../../../../../packages/server/src/api/controllers/public/mapping/types" import generator from "../TestConfiguration/generator" -export const generateTable = (overrides = {}): CreateTableParams => ({ +export const generateTable = ( + overrides: Partial = {} +): CreateTableParams => ({ name: generator.word(), primaryDisplay: "sasa", schema: { @@ -20,7 +24,7 @@ export const generateTable = (overrides = {}): CreateTableParams => ({ }, "Created By": { autocolumn: true, - fieldName: "test12-Created By", + fieldName: generator.word(), name: "Created By", relationshipType: "many-to-many", tableId: "ta_users", @@ -37,7 +41,7 @@ export const generateTable = (overrides = {}): CreateTableParams => ({ }, "Updated By": { autocolumn: true, - fieldName: "test12-Updated By", + fieldName: generator.word(), name: "Updated By", relationshipType: "many-to-many", tableId: "ta_users", @@ -47,10 +51,10 @@ export const generateTable = (overrides = {}): CreateTableParams => ({ ...overrides, }) -export const generateRow = (overrides = {}): CreateRowParams => ({ +export const generateRow = (overrides: Partial = {}): CreateRowParams => ({ type: "row", tableId: "seed_table", - sasa: "Mike", - relationship: ["ro_ta_"], + sasa: 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 52124024e7..aaca5f2480 100644 --- a/qa-core/src/config/public-api/fixtures/users.ts +++ b/qa-core/src/config/public-api/fixtures/users.ts @@ -1,7 +1,10 @@ -import { CreateUserParams } from "../../../../../packages/server/src/api/controllers/public/mapping/types" +import { + CreateUserParams, + User, +} from "../../../../../packages/server/src/api/controllers/public/mapping/types" import generator from "../TestConfiguration/generator" -const generate = (overrides = {}): CreateUserParams => ({ +const generate = (overrides: Partial = {}): CreateUserParams => ({ email: generator.email(), roles: { [generator.string({ length: 32, alpha: true, numeric: true })]: 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 1031f511b4..59a24861af 100644 --- a/qa-core/src/tests/public-api/applications/applications.spec.ts +++ b/qa-core/src/tests/public-api/applications/applications.spec.ts @@ -9,6 +9,8 @@ describe("Public API - /applications endpoints", () => { beforeAll(async () => { await config.beforeAll() + const [response, app] = await config.applications.seed() + config.context = app }) afterAll(async () => { @@ -17,7 +19,6 @@ describe("Public API - /applications endpoints", () => { it("POST - Create an application", async () => { const [response, app] = await config.applications.create(generateApp()) - config.context = app expect(response).toHaveStatusCode(200) }) 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 66d46208cc..f34c4cde29 100644 --- a/qa-core/src/tests/public-api/tables/rows.spec.ts +++ b/qa-core/src/tests/public-api/tables/rows.spec.ts @@ -12,11 +12,14 @@ describe("Public API - /rows endpoints", () => { await config.beforeAll() const [appResp, app] = await config.applications.seed() - config.tables.appId = app._id - const [tableResp, table] = await config.tables.seed() + config.tables.api.appId = app._id + config.rows.api.appId = app._id - config.rows.appId = app._id + const [tableResp, table] = await config.tables.seed() config.rows.tableId = table._id + + const [response, row] = await config.rows.create(generateRow()) + config.context = row }) afterAll(async () => { @@ -25,7 +28,6 @@ describe("Public API - /rows endpoints", () => { it("POST - Create a row", async () => { const [response, row] = await config.rows.create(generateRow()) - config.context = row expect(response).toHaveStatusCode(200) }) 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 9dfdc8cdc0..c2f50d3e8e 100644 --- a/qa-core/src/tests/public-api/tables/tables.spec.ts +++ b/qa-core/src/tests/public-api/tables/tables.spec.ts @@ -9,8 +9,11 @@ describe("Public API - /tables endpoints", () => { beforeAll(async () => { await config.beforeAll() - const [_, app] = await config.applications.seed() - config.tables.appId = app._id + const [appResp, app] = await config.applications.seed() + config.tables.api.appId = app._id + + const [tableResp, table] = await config.tables.seed() + config.context = table }) afterAll(async () => { @@ -19,7 +22,6 @@ describe("Public API - /tables endpoints", () => { it("POST - Create a table", async () => { const [response, table] = await config.tables.create(generateTable()) - config.context = table expect(response).toHaveStatusCode(200) }) 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 95d257c0f9..b981deb786 100644 --- a/qa-core/src/tests/public-api/users/users.spec.ts +++ b/qa-core/src/tests/public-api/users/users.spec.ts @@ -9,6 +9,8 @@ describe("Public API - /users endpoints", () => { beforeAll(async () => { await config.beforeAll() + const [response, user] = await config.users.seed() + config.context = user }) afterAll(async () => { @@ -17,7 +19,6 @@ describe("Public API - /users endpoints", () => { it("POST - Create a user", async () => { const [response, user] = await config.users.create(generateUser()) - config.context = user expect(response).toHaveStatusCode(200) })