From 6d99caf2a66e67e88dd6c20a2a983fd1ee84ef44 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Thu, 10 Nov 2022 09:45:02 +0000 Subject: [PATCH] Remove logic from endpoint methods --- .../TestConfiguration/applications.ts | 51 +++++++++++-------- .../applications/applications.spec.ts | 11 ++-- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/qa-core/src/config/internal-api/TestConfiguration/applications.ts b/qa-core/src/config/internal-api/TestConfiguration/applications.ts index c9930e9981..cb0558222e 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/applications.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/applications.ts @@ -10,21 +10,23 @@ import { UnpublishAppResponse } from "../fixtures/types/unpublishAppResponse" export default class AppApi { api: InternalAPIClient - appCreated: boolean constructor(apiClient: InternalAPIClient) { this.api = apiClient - this.appCreated = false } - async fetch(): Promise<[Response, Application[]]> { + async fetchEmptyAppList(): Promise<[Response, Application[]]> { const response = await this.api.get(`/applications?status=all`) const json = await response.json() expect(response).toHaveStatusCode(200) - if (this.appCreated) { - expect(json.length).toBeGreaterThanOrEqual(1) - } else { - expect(json.length).toEqual(0) - } + expect(json.length).toEqual(0) + return [response, json] + } + + async fetchAllApplications(): Promise<[Response, Application[]]> { + const response = await this.api.get(`/applications?status=all`) + const json = await response.json() + expect(response).toHaveStatusCode(200) + expect(json.length).toBeGreaterThanOrEqual(1) return [response, json] } @@ -62,7 +64,6 @@ export default class AppApi { const json = await response.json() expect(response).toHaveStatusCode(200) expect(json._id).toBeDefined() - this.appCreated = true return json } @@ -79,6 +80,7 @@ export default class AppApi { return [response, json] } + // TODO async updateClient( appId: string, body: any @@ -91,24 +93,29 @@ export default class AppApi { return [response, json] } - async revert(appId: string, negativeTest?: boolean): Promise<[Response, responseMessage]> { + async revertPublished(appId: string): Promise<[Response, responseMessage]> { const response = await this.api.post(`/dev/${appId}/revert`) const json = await response.json() - if (negativeTest) { - expect(response).toHaveStatusCode(400) - expect(json).toEqual({ - message: "App has not yet been deployed", - status: 400, - }) - } else { - expect(response).toHaveStatusCode(200) - expect(json).toEqual({ - message: "Reverted changes successfully.", - }) - } + expect(response).toHaveStatusCode(200) + expect(json).toEqual({ + message: "Reverted changes successfully.", + }) return [response, json] } + async revertUnpublished(appId: string): Promise<[Response, responseMessage]> { + const response = await this.api.post(`/dev/${appId}/revert`) + const json = await response.json() + expect(response).toHaveStatusCode(400) + expect(json).toEqual({ + message: "App has not yet been deployed", + status: 400, + }) + return [response, json] + } + + + async delete(appId: string): Promise<[Response, any]> { const response = await this.api.del(`/applications/${appId}`) const json = await response.json() diff --git a/qa-core/src/tests/internal-api/applications/applications.spec.ts b/qa-core/src/tests/internal-api/applications/applications.spec.ts index 48e2727926..4b9b66ec65 100644 --- a/qa-core/src/tests/internal-api/applications/applications.spec.ts +++ b/qa-core/src/tests/internal-api/applications/applications.spec.ts @@ -29,7 +29,7 @@ describe("Internal API - Application creation, update, publish and delete", () = }) } it("Get applications without applications", async () => { - await config.applications.fetch() + await config.applications.fetchEmptyAppList() }) it("Get all Applications after creating an application", async () => { @@ -38,7 +38,7 @@ describe("Internal API - Application creation, update, publish and delete", () = useTemplate: false, }) - await config.applications.fetch() + await config.applications.fetchAllApplications() }) it("Get application details", async () => { @@ -122,9 +122,8 @@ describe("Internal API - Application creation, update, publish and delete", () = const app = await config.applications.create(generateApp()) config.applications.api.appId = app.appId - await config.applications.revert( - app.appId, - true + await config.applications.revertUnpublished( + app.appId ) }) @@ -142,7 +141,7 @@ describe("Internal API - Application creation, update, publish and delete", () = ) // // Revert the app to published state - await config.applications.revert( + await config.applications.revertPublished( app.appId )