From 2c2cd4c9f6777646344f1ff899e8668fe2365fb3 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Tue, 4 Oct 2022 16:11:19 +0100 Subject: [PATCH 01/12] Add Sync endpoint --- .../config/internal-api/TestConfiguration/applications.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/qa-core/src/config/internal-api/TestConfiguration/applications.ts b/qa-core/src/config/internal-api/TestConfiguration/applications.ts index 10e4a6657b..4247b06d2a 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/applications.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/applications.ts @@ -50,4 +50,11 @@ export default class AppApi { const json = await response.json() return [response, json.data] } + + async sync(appId: string): Promise<[Response, any]> { + const response = await this.api.post(`/applications/${appId}/sync`) + const json = await response.json() + return [response, json] + } + } From ea8122d5a0da6f48be964b3b93203e560d56db48 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Tue, 4 Oct 2022 17:12:38 +0100 Subject: [PATCH 02/12] Add missing applications endpoints --- .../TestConfiguration/applications.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/qa-core/src/config/internal-api/TestConfiguration/applications.ts b/qa-core/src/config/internal-api/TestConfiguration/applications.ts index 26375154e9..82b85372c6 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/applications.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/applications.ts @@ -53,4 +53,29 @@ export default class AppApi { return [response, json] } + async update(appId: string, body: any): Promise<[Response, Application]> { + const response = await this.api.put(`/applications/${appId}/client/update`, { body }) + const json = await response.json() + return [response, json] + } + + async revert(appId: string): Promise<[Response, Application]> { + const response = await this.api.post(`/applications/${appId}/client/revert`) + const json = await response.json() + return [response, json] + } + + async delete(appId: string): Promise<[Response, any]> { + const response = await this.api.del(`/applications/${appId}`) + const json = await response.json() + return [response, json] + } + + async getAppDefinition(appId: string): Promise<[Response, any]> { + const response = await this.api.get(`/applications/${appId}/definition`) + const json = await response.json() + return [response, json] + } + + } From ea029291309b5df1bc4284b6af0c22022a8ab74e Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Fri, 7 Oct 2022 12:19:00 +0100 Subject: [PATCH 03/12] Add tests for endpoints --- .../TestConfiguration/applications.ts | 8 ++- .../internal-api/applications/create.spec.ts | 67 +++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/qa-core/src/config/internal-api/TestConfiguration/applications.ts b/qa-core/src/config/internal-api/TestConfiguration/applications.ts index 82b85372c6..3b577abf5e 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/applications.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/applications.ts @@ -53,7 +53,7 @@ export default class AppApi { return [response, json] } - async update(appId: string, body: any): Promise<[Response, Application]> { + async updateClient(appId: string, body: any): Promise<[Response, Application]> { const response = await this.api.put(`/applications/${appId}/client/update`, { body }) const json = await response.json() return [response, json] @@ -77,5 +77,11 @@ export default class AppApi { return [response, json] } + async update(appId: string, body: any): Promise<[Response, Application]> { + const response = await this.api.put(`/applications/${appId}`, { body }) + const json = await response.json() + return [response, json] + } + } diff --git a/qa-core/src/tests/internal-api/applications/create.spec.ts b/qa-core/src/tests/internal-api/applications/create.spec.ts index 2c934e0bd7..b447a95459 100644 --- a/qa-core/src/tests/internal-api/applications/create.spec.ts +++ b/qa-core/src/tests/internal-api/applications/create.spec.ts @@ -84,4 +84,71 @@ describe("Internal API - /applications endpoints", () => { await config.applications.canRender() expect(publishedAppRenders).toBe(true) }) + + it("POST - Sync application before deployment", async () => { + const [response, app] = await config.applications.create(generateApp()) + expect(response).toHaveStatusCode(200) + expect(app.appId).toBeDefined() + config.applications.api.appId = app.appId + + const [syncResponse, sync] = await config.applications.sync(app.appId ? app.appId : "") + expect(syncResponse).toHaveStatusCode(200) + expect(sync).toEqual({ + message: "App sync not required, app not deployed." + }) + }) + + it("POST - Sync application after deployment", async () => { + const [response, app] = await config.applications.create(generateApp()) + expect(response).toHaveStatusCode(200) + expect(app.appId).toBeDefined() + config.applications.api.appId = app.appId + + // publish app + await config.applications.publish() + + const [syncResponse, sync] = await config.applications.sync(app.appId ? app.appId : "") + expect(syncResponse).toHaveStatusCode(200) + expect(sync).toEqual({ + message: "App sync completed successfully." + }) + }) + + it("PUT - Update an application", async () => { + const [response, app] = await config.applications.create(generateApp()) + expect(response).toHaveStatusCode(200) + expect(app.appId).toBeDefined() + + }) + + + it.skip("POST - Revert Changes", async () => { + const [response, app] = await config.applications.create(generateApp()) + expect(response).toHaveStatusCode(200) + expect(app.appId).toBeDefined() + + // publish app + await config.applications.publish() + + const [updateResponse, updatedApp] = await config.applications.update(app.appId ? app.appId : "", { + name: generator.word(), + }) + expect(updateResponse).toHaveStatusCode(200) + expect(updatedApp.name).not.toEqual(app.name) + + const [revertResponse, revert] = await config.applications.revert(app.appId ? app.appId : "") + expect(revertResponse).toHaveStatusCode(200) + expect(revert).toEqual({ + message: "App reverted successfully." + }) + }) + + it("DELETE - Delete an application", async () => { + const [response, app] = await config.applications.create(generateApp()) + expect(response).toHaveStatusCode(200) + expect(app.appId).toBeDefined() + + const [deleteResponse] = await config.applications.delete(app.appId ? app.appId : "") + expect(deleteResponse).toHaveStatusCode(200) + }) }) From 970ba0315e5059cf7a934e0542b3584e8167fefe Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Fri, 7 Oct 2022 18:05:58 +0100 Subject: [PATCH 04/12] Add tests for revert endpoint --- .../TestConfiguration/applications.ts | 13 ++++- .../config/internal-api/fixtures/screens.ts | 34 +++++++++++++ .../internal-api/applications/create.spec.ts | 51 +++++++++++++++---- 3 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 qa-core/src/config/internal-api/fixtures/screens.ts diff --git a/qa-core/src/config/internal-api/TestConfiguration/applications.ts b/qa-core/src/config/internal-api/TestConfiguration/applications.ts index 3b577abf5e..8c88819ef5 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/applications.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/applications.ts @@ -29,7 +29,7 @@ export default class AppApi { return [response, json] } - async publish(): Promise<[Response, string]> { + async publish(): Promise<[Response, any]> { const response = await this.api.post("/deploy") const json = await response.json() return [response, json] @@ -82,6 +82,17 @@ export default class AppApi { const json = await response.json() return [response, json] } + async addScreentoApp(body: any): Promise<[Response, Application]> { + const response = await this.api.post(`/screens`, { body }) + const json = await response.json() + return [response, json] + } + + async getRoutes(): Promise<[Response, any]> { + const response = await this.api.get(`/routing`) + const json = await response.json() + return [response, json] + } } diff --git a/qa-core/src/config/internal-api/fixtures/screens.ts b/qa-core/src/config/internal-api/fixtures/screens.ts new file mode 100644 index 0000000000..2a2cc1eada --- /dev/null +++ b/qa-core/src/config/internal-api/fixtures/screens.ts @@ -0,0 +1,34 @@ +import generator from "../../generator" + +const randomId = generator.guid() + +const generateScreen = (): any => ({ + showNavigation: true, + width: "Large", + props: { + _id: randomId, + _component: + "@budibase/standard-components/container", + _styles: { + normal: {}, + hover: {}, + active: {}, + selected: {} + }, + _children: [], + _instanceName: "New Screen", + direction: "column", + hAlign: "stretch", + vAlign: "top", + size: "grow", + gap: "M" + }, routing: { + route: "/test", + roleId: "BASIC", + homeScreen: false + }, + name: randomId, + template: "createFromScratch" +}) + +export default generateScreen diff --git a/qa-core/src/tests/internal-api/applications/create.spec.ts b/qa-core/src/tests/internal-api/applications/create.spec.ts index b447a95459..4b9a21319d 100644 --- a/qa-core/src/tests/internal-api/applications/create.spec.ts +++ b/qa-core/src/tests/internal-api/applications/create.spec.ts @@ -4,6 +4,7 @@ import { db } from "@budibase/backend-core" import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" import generateApp from "../../../config/internal-api/fixtures/applications" import generator from "../../../config/generator" +import generateScreen from "../../../config/internal-api/fixtures/screens" describe("Internal API - /applications endpoints", () => { const api = new InternalAPIClient() @@ -118,29 +119,57 @@ describe("Internal API - /applications endpoints", () => { const [response, app] = await config.applications.create(generateApp()) expect(response).toHaveStatusCode(200) expect(app.appId).toBeDefined() - - }) - - - it.skip("POST - Revert Changes", async () => { - const [response, app] = await config.applications.create(generateApp()) - expect(response).toHaveStatusCode(200) - expect(app.appId).toBeDefined() - - // publish app - await config.applications.publish() + config.applications.api.appId = app.appId const [updateResponse, updatedApp] = await config.applications.update(app.appId ? app.appId : "", { name: generator.word(), }) expect(updateResponse).toHaveStatusCode(200) expect(updatedApp.name).not.toEqual(app.name) + }) + + // Skip this test because of the if line 44 in InternalAPIClient.ts + it.skip("POST - Revert Changes without changes", async () => { + const [response, app] = await config.applications.create(generateApp()) + expect(response).toHaveStatusCode(200) + expect(app.appId).toBeDefined() + config.applications.api.appId = app.appId + + const [revertResponse, revert] = await config.applications.revert(app.appId ? app.appId : "") + expect(revertResponse).toHaveStatusCode(400) + expect(revert).toEqual({ + message: "There is no version to revert to", + }) + }) + + it("POST - Revert Changes", async () => { + const [response, app] = await config.applications.create(generateApp()) + expect(response).toHaveStatusCode(200) + expect(app.appId).toBeDefined() + config.applications.api.appId = app.appId + + // publish app + const [publishResponse, publish] = await config.applications.publish() + expect(publishResponse).toHaveStatusCode(200) + expect(publish.status).toEqual("SUCCESS") + + // Change/add component to the app + const [screenResponse, screen] = await config.applications.addScreentoApp(generateScreen()) + expect(screenResponse).toHaveStatusCode(200) + expect(screen._id).toBeDefined() + const [revertResponse, revert] = await config.applications.revert(app.appId ? app.appId : "") expect(revertResponse).toHaveStatusCode(200) expect(revert).toEqual({ message: "App reverted successfully." }) + + // Check screen is removed + const [routesResponse, routes] = await config.applications.getRoutes() + expect(routesResponse).toHaveStatusCode(200) + expect(routes.routes["/test"]).toBeUndefined() + }) it("DELETE - Delete an application", async () => { From 052bc0aeedcff577e6cf148c246a34863d9c9ac5 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Sun, 9 Oct 2022 19:31:35 +0100 Subject: [PATCH 05/12] ensure correct revert endpoint being hit, update call to revert --- packages/server/src/api/controllers/dev.js | 2 +- packages/server/src/api/controllers/table/internal.ts | 3 ++- .../config/internal-api/TestConfiguration/applications.ts | 6 +++--- qa-core/src/tests/internal-api/applications/create.spec.ts | 6 +++--- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/server/src/api/controllers/dev.js b/packages/server/src/api/controllers/dev.js index e5582be5b3..c8f134756b 100644 --- a/packages/server/src/api/controllers/dev.js +++ b/packages/server/src/api/controllers/dev.js @@ -103,7 +103,7 @@ exports.revert = async ctx => { target: appId, }) try { - if (!env.isCypress()) { + if (env.COUCH_DB_URL) { // in-memory db stalls on rollback await replication.rollback() } diff --git a/packages/server/src/api/controllers/table/internal.ts b/packages/server/src/api/controllers/table/internal.ts index 22c9b6dc55..7e55c71aea 100644 --- a/packages/server/src/api/controllers/table/internal.ts +++ b/packages/server/src/api/controllers/table/internal.ts @@ -18,6 +18,7 @@ import { Table } from "@budibase/types" import { quotas } from "@budibase/pro" import { isEqual } from "lodash" import { cloneDeep } from "lodash/fp" +import env from "../../../environment" function checkAutoColumns(table: Table, oldTable: Table) { if (!table.schema) { @@ -167,7 +168,7 @@ export async function destroy(ctx: any) { await db.remove(tableToDelete) // remove table search index - if (!isTest()) { + if (!isTest() || env.COUCH_DB_URL) { const currentIndexes = await db.getIndexes() const existingIndex = currentIndexes.indexes.find( (existing: any) => existing.name === `search:${ctx.params.tableId}` diff --git a/qa-core/src/config/internal-api/TestConfiguration/applications.ts b/qa-core/src/config/internal-api/TestConfiguration/applications.ts index 8c88819ef5..0372e50b0b 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/applications.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/applications.ts @@ -59,8 +59,8 @@ export default class AppApi { return [response, json] } - async revert(appId: string): Promise<[Response, Application]> { - const response = await this.api.post(`/applications/${appId}/client/revert`) + async revert(appId: string): Promise<[Response, { message: string }]> { + const response = await this.api.post(`/dev/${appId}/revert`) const json = await response.json() return [response, json] } @@ -82,8 +82,8 @@ export default class AppApi { const json = await response.json() return [response, json] } - async addScreentoApp(body: any): Promise<[Response, Application]> { + async addScreentoApp(body: any): Promise<[Response, Application]> { const response = await this.api.post(`/screens`, { body }) const json = await response.json() return [response, json] diff --git a/qa-core/src/tests/internal-api/applications/create.spec.ts b/qa-core/src/tests/internal-api/applications/create.spec.ts index 4b9a21319d..fc7901cc6f 100644 --- a/qa-core/src/tests/internal-api/applications/create.spec.ts +++ b/qa-core/src/tests/internal-api/applications/create.spec.ts @@ -158,11 +158,11 @@ describe("Internal API - /applications endpoints", () => { expect(screenResponse).toHaveStatusCode(200) expect(screen._id).toBeDefined() - - const [revertResponse, revert] = await config.applications.revert(app.appId ? app.appId : "") + // // Revert the app to published state + const [revertResponse, revert] = await config.applications.revert(app.appId as string) expect(revertResponse).toHaveStatusCode(200) expect(revert).toEqual({ - message: "App reverted successfully." + message: "Reverted changes successfully." }) // Check screen is removed From e55d116c5ec475be50b7ff2b6ff70b65d350456e Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Mon, 10 Oct 2022 14:24:34 +0100 Subject: [PATCH 06/12] Fix revert test with 400 status --- qa-core/src/tests/internal-api/applications/create.spec.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/qa-core/src/tests/internal-api/applications/create.spec.ts b/qa-core/src/tests/internal-api/applications/create.spec.ts index fc7901cc6f..1595df5080 100644 --- a/qa-core/src/tests/internal-api/applications/create.spec.ts +++ b/qa-core/src/tests/internal-api/applications/create.spec.ts @@ -129,7 +129,7 @@ describe("Internal API - /applications endpoints", () => { }) // Skip this test because of the if line 44 in InternalAPIClient.ts - it.skip("POST - Revert Changes without changes", async () => { + it("POST - Revert Changes without changes", async () => { const [response, app] = await config.applications.create(generateApp()) expect(response).toHaveStatusCode(200) expect(app.appId).toBeDefined() @@ -138,10 +138,12 @@ describe("Internal API - /applications endpoints", () => { const [revertResponse, revert] = await config.applications.revert(app.appId ? app.appId : "") expect(revertResponse).toHaveStatusCode(400) expect(revert).toEqual({ - message: "There is no version to revert to", + message: "App has not yet been deployed", + status: 400 }) }) + it("POST - Revert Changes", async () => { const [response, app] = await config.applications.create(generateApp()) expect(response).toHaveStatusCode(200) From 12eb99600d39e3113c68eb1a6603070033b696a7 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Mon, 10 Oct 2022 14:39:12 +0100 Subject: [PATCH 07/12] Remove comment --- qa-core/src/tests/internal-api/applications/create.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/qa-core/src/tests/internal-api/applications/create.spec.ts b/qa-core/src/tests/internal-api/applications/create.spec.ts index 1595df5080..be484bc44d 100644 --- a/qa-core/src/tests/internal-api/applications/create.spec.ts +++ b/qa-core/src/tests/internal-api/applications/create.spec.ts @@ -128,7 +128,6 @@ describe("Internal API - /applications endpoints", () => { expect(updatedApp.name).not.toEqual(app.name) }) - // Skip this test because of the if line 44 in InternalAPIClient.ts it("POST - Revert Changes without changes", async () => { const [response, app] = await config.applications.create(generateApp()) expect(response).toHaveStatusCode(200) From 2f5ab092feb19ad5644b245999127343c562fb0f Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Tue, 11 Oct 2022 15:06:04 +0100 Subject: [PATCH 08/12] Add test for appDefinition --- .../internal-api/applications/create.spec.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/qa-core/src/tests/internal-api/applications/create.spec.ts b/qa-core/src/tests/internal-api/applications/create.spec.ts index be484bc44d..a67f189c7d 100644 --- a/qa-core/src/tests/internal-api/applications/create.spec.ts +++ b/qa-core/src/tests/internal-api/applications/create.spec.ts @@ -181,4 +181,23 @@ describe("Internal API - /applications endpoints", () => { const [deleteResponse] = await config.applications.delete(app.appId ? app.appId : "") expect(deleteResponse).toHaveStatusCode(200) }) + + it("GET - App Definition", async () => { + const [response, app] = await config.applications.create(generateApp()) + expect(response).toHaveStatusCode(200) + expect(app.appId).toBeDefined() + config.applications.api.appId = app.appId + + const [definitionResponse, definition] = await config.applications.getAppDefinition(app.appId ? app.appId : "") + expect(definitionResponse).toHaveStatusCode(200) + expect(definition).toEqual({ + appId: app.appId, + appUrl: app.url, + name: app.name, + pages: [], + pagesById: {}, + routes: {}, + theme: {}, + }) + }) }) From 8ce7ca1bb2e6bd49d9606b359c010aae8b0cecfd Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Tue, 11 Oct 2022 15:08:08 +0100 Subject: [PATCH 09/12] Add types for response --- .../config/internal-api/TestConfiguration/applications.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/qa-core/src/config/internal-api/TestConfiguration/applications.ts b/qa-core/src/config/internal-api/TestConfiguration/applications.ts index 0372e50b0b..7d17250e2b 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/applications.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/applications.ts @@ -4,6 +4,8 @@ import { Response } from "node-fetch" import InternalAPIClient from "./InternalAPIClient" import FormData from "form-data" +type messageResponse = { message: string } + export default class AppApi { api: InternalAPIClient @@ -47,7 +49,7 @@ export default class AppApi { return [response, json.data] } - async sync(appId: string): Promise<[Response, any]> { + async sync(appId: string): Promise<[Response, messageResponse]> { const response = await this.api.post(`/applications/${appId}/sync`) const json = await response.json() return [response, json] @@ -59,7 +61,7 @@ export default class AppApi { return [response, json] } - async revert(appId: string): Promise<[Response, { message: string }]> { + async revert(appId: string): Promise<[Response, messageResponse]> { const response = await this.api.post(`/dev/${appId}/revert`) const json = await response.json() return [response, json] From dd914d31dbd6f86ca58459c72e201097aa657ff6 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Tue, 11 Oct 2022 16:21:05 +0100 Subject: [PATCH 10/12] Remove Test and fix types --- .../internal-api/applications/create.spec.ts | 30 ++++--------------- 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/qa-core/src/tests/internal-api/applications/create.spec.ts b/qa-core/src/tests/internal-api/applications/create.spec.ts index a67f189c7d..bed1b43790 100644 --- a/qa-core/src/tests/internal-api/applications/create.spec.ts +++ b/qa-core/src/tests/internal-api/applications/create.spec.ts @@ -92,7 +92,7 @@ describe("Internal API - /applications endpoints", () => { expect(app.appId).toBeDefined() config.applications.api.appId = app.appId - const [syncResponse, sync] = await config.applications.sync(app.appId ? app.appId : "") + const [syncResponse, sync] = await config.applications.sync(app.appId) expect(syncResponse).toHaveStatusCode(200) expect(sync).toEqual({ message: "App sync not required, app not deployed." @@ -108,7 +108,7 @@ describe("Internal API - /applications endpoints", () => { // publish app await config.applications.publish() - const [syncResponse, sync] = await config.applications.sync(app.appId ? app.appId : "") + const [syncResponse, sync] = await config.applications.sync(app.appId) expect(syncResponse).toHaveStatusCode(200) expect(sync).toEqual({ message: "App sync completed successfully." @@ -121,7 +121,7 @@ describe("Internal API - /applications endpoints", () => { expect(app.appId).toBeDefined() config.applications.api.appId = app.appId - const [updateResponse, updatedApp] = await config.applications.update(app.appId ? app.appId : "", { + const [updateResponse, updatedApp] = await config.applications.update(app.appId, { name: generator.word(), }) expect(updateResponse).toHaveStatusCode(200) @@ -134,7 +134,7 @@ describe("Internal API - /applications endpoints", () => { expect(app.appId).toBeDefined() config.applications.api.appId = app.appId - const [revertResponse, revert] = await config.applications.revert(app.appId ? app.appId : "") + const [revertResponse, revert] = await config.applications.revert(app.appId) expect(revertResponse).toHaveStatusCode(400) expect(revert).toEqual({ message: "App has not yet been deployed", @@ -160,7 +160,7 @@ describe("Internal API - /applications endpoints", () => { expect(screen._id).toBeDefined() // // Revert the app to published state - const [revertResponse, revert] = await config.applications.revert(app.appId as string) + const [revertResponse, revert] = await config.applications.revert(app.appId) expect(revertResponse).toHaveStatusCode(200) expect(revert).toEqual({ message: "Reverted changes successfully." @@ -178,26 +178,8 @@ describe("Internal API - /applications endpoints", () => { expect(response).toHaveStatusCode(200) expect(app.appId).toBeDefined() - const [deleteResponse] = await config.applications.delete(app.appId ? app.appId : "") + const [deleteResponse] = await config.applications.delete(app.appId) expect(deleteResponse).toHaveStatusCode(200) }) - it("GET - App Definition", async () => { - const [response, app] = await config.applications.create(generateApp()) - expect(response).toHaveStatusCode(200) - expect(app.appId).toBeDefined() - config.applications.api.appId = app.appId - - const [definitionResponse, definition] = await config.applications.getAppDefinition(app.appId ? app.appId : "") - expect(definitionResponse).toHaveStatusCode(200) - expect(definition).toEqual({ - appId: app.appId, - appUrl: app.url, - name: app.name, - pages: [], - pagesById: {}, - routes: {}, - theme: {}, - }) - }) }) From 07359370e6e722977694407260a79341f0762c83 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Tue, 11 Oct 2022 16:24:43 +0100 Subject: [PATCH 11/12] Fix Identation --- .../config/internal-api/fixtures/screens.ts | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/qa-core/src/config/internal-api/fixtures/screens.ts b/qa-core/src/config/internal-api/fixtures/screens.ts index 2a2cc1eada..28e58e8eb8 100644 --- a/qa-core/src/config/internal-api/fixtures/screens.ts +++ b/qa-core/src/config/internal-api/fixtures/screens.ts @@ -3,32 +3,32 @@ import generator from "../../generator" const randomId = generator.guid() const generateScreen = (): any => ({ - showNavigation: true, - width: "Large", - props: { - _id: randomId, - _component: - "@budibase/standard-components/container", - _styles: { - normal: {}, - hover: {}, - active: {}, - selected: {} - }, - _children: [], - _instanceName: "New Screen", - direction: "column", - hAlign: "stretch", - vAlign: "top", - size: "grow", - gap: "M" - }, routing: { - route: "/test", - roleId: "BASIC", - homeScreen: false + showNavigation: true, + width: "Large", + props: { + _id: randomId, + _component: "@budibase/standard-components/container", + _styles: { + normal: {}, + hover: {}, + active: {}, + selected: {}, }, - name: randomId, - template: "createFromScratch" + _children: [], + _instanceName: "New Screen", + direction: "column", + hAlign: "stretch", + vAlign: "top", + size: "grow", + gap: "M", + }, + routing: { + route: "/test", + roleId: "BASIC", + homeScreen: false, + }, + name: randomId, + template: "createFromScratch", }) export default generateScreen From 4090dd2dfe07311fd1b8f5ab74ccf68e834107bf Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Tue, 11 Oct 2022 16:47:02 +0100 Subject: [PATCH 12/12] Add types for Responses --- .../TestConfiguration/applications.ts | 15 ++++++--------- .../internal-api/fixtures/types/appPackage.ts | 9 +++++++++ .../internal-api/fixtures/types/deploy.ts | 6 ++++++ .../internal-api/fixtures/types/routing.ts | 17 +++++++++++++++++ 4 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 qa-core/src/config/internal-api/fixtures/types/appPackage.ts create mode 100644 qa-core/src/config/internal-api/fixtures/types/deploy.ts create mode 100644 qa-core/src/config/internal-api/fixtures/types/routing.ts diff --git a/qa-core/src/config/internal-api/TestConfiguration/applications.ts b/qa-core/src/config/internal-api/TestConfiguration/applications.ts index 7d17250e2b..36abb7db36 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/applications.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/applications.ts @@ -3,6 +3,9 @@ import { App } from "@budibase/types" import { Response } from "node-fetch" import InternalAPIClient from "./InternalAPIClient" import FormData from "form-data" +import { RouteConfig } from "../fixtures/types/routing" +import { AppPackageResponse } from "../fixtures/types/appPackage" +import { DeployConfig } from "../fixtures/types/deploy" type messageResponse = { message: string } @@ -25,13 +28,13 @@ export default class AppApi { return [response, Object.keys(json.routes).length > 0] } - async getAppPackage(appId: string): Promise<[Response, any]> { + async getAppPackage(appId: string): Promise<[Response, AppPackageResponse]> { const response = await this.api.get(`/applications/${appId}/appPackage`) const json = await response.json() return [response, json] } - async publish(): Promise<[Response, any]> { + async publish(): Promise<[Response, DeployConfig]> { const response = await this.api.post("/deploy") const json = await response.json() return [response, json] @@ -73,12 +76,6 @@ export default class AppApi { return [response, json] } - async getAppDefinition(appId: string): Promise<[Response, any]> { - const response = await this.api.get(`/applications/${appId}/definition`) - const json = await response.json() - return [response, json] - } - async update(appId: string, body: any): Promise<[Response, Application]> { const response = await this.api.put(`/applications/${appId}`, { body }) const json = await response.json() @@ -91,7 +88,7 @@ export default class AppApi { return [response, json] } - async getRoutes(): Promise<[Response, any]> { + async getRoutes(): Promise<[Response, RouteConfig]> { const response = await this.api.get(`/routing`) const json = await response.json() return [response, json] diff --git a/qa-core/src/config/internal-api/fixtures/types/appPackage.ts b/qa-core/src/config/internal-api/fixtures/types/appPackage.ts new file mode 100644 index 0000000000..e21e91f78f --- /dev/null +++ b/qa-core/src/config/internal-api/fixtures/types/appPackage.ts @@ -0,0 +1,9 @@ +import { Application } from "@budibase/server/api/controllers/public/mapping/types" +import { Layout } from "@budibase/types" +import { Screen } from "@budibase/types" +// Create type for getAppPackage response +export interface AppPackageResponse { + application: Partial, + layout: Layout, + screens: Screen[] +} diff --git a/qa-core/src/config/internal-api/fixtures/types/deploy.ts b/qa-core/src/config/internal-api/fixtures/types/deploy.ts new file mode 100644 index 0000000000..f859f3255b --- /dev/null +++ b/qa-core/src/config/internal-api/fixtures/types/deploy.ts @@ -0,0 +1,6 @@ + +export interface DeployConfig { + appUrl: string, + status: string, + "_id": string +} diff --git a/qa-core/src/config/internal-api/fixtures/types/routing.ts b/qa-core/src/config/internal-api/fixtures/types/routing.ts new file mode 100644 index 0000000000..0cddcdffb9 --- /dev/null +++ b/qa-core/src/config/internal-api/fixtures/types/routing.ts @@ -0,0 +1,17 @@ +export interface RouteConfig { + routes: Record +} + +export interface Route { + subpaths: Record +} + +export interface Subpath { + screens: ScreenRouteConfig +} + +export interface ScreenRouteConfig { + BASIC?: string + POWER?: string + ADMIN?: string +} \ No newline at end of file