From e343aab655a9459bc7da375a12024a3c188be4c4 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Fri, 7 Oct 2022 12:19:00 +0100 Subject: [PATCH] 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) + }) })