Remove logic from endpoint methods
This commit is contained in:
parent
517893da26
commit
6d99caf2a6
|
@ -10,21 +10,23 @@ import { UnpublishAppResponse } from "../fixtures/types/unpublishAppResponse"
|
||||||
|
|
||||||
export default class AppApi {
|
export default class AppApi {
|
||||||
api: InternalAPIClient
|
api: InternalAPIClient
|
||||||
appCreated: boolean
|
|
||||||
constructor(apiClient: InternalAPIClient) {
|
constructor(apiClient: InternalAPIClient) {
|
||||||
this.api = apiClient
|
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 response = await this.api.get(`/applications?status=all`)
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
expect(response).toHaveStatusCode(200)
|
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]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +64,6 @@ export default class AppApi {
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
expect(response).toHaveStatusCode(200)
|
expect(response).toHaveStatusCode(200)
|
||||||
expect(json._id).toBeDefined()
|
expect(json._id).toBeDefined()
|
||||||
this.appCreated = true
|
|
||||||
return json
|
return json
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +80,7 @@ export default class AppApi {
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
async updateClient(
|
async updateClient(
|
||||||
appId: string,
|
appId: string,
|
||||||
body: any
|
body: any
|
||||||
|
@ -91,24 +93,29 @@ export default class AppApi {
|
||||||
return [response, json]
|
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()
|
||||||
|
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 response = await this.api.post(`/dev/${appId}/revert`)
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
if (negativeTest) {
|
|
||||||
expect(response).toHaveStatusCode(400)
|
expect(response).toHaveStatusCode(400)
|
||||||
expect(json).toEqual({
|
expect(json).toEqual({
|
||||||
message: "App has not yet been deployed",
|
message: "App has not yet been deployed",
|
||||||
status: 400,
|
status: 400,
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
expect(response).toHaveStatusCode(200)
|
|
||||||
expect(json).toEqual({
|
|
||||||
message: "Reverted changes successfully.",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async delete(appId: string): Promise<[Response, any]> {
|
async delete(appId: string): Promise<[Response, any]> {
|
||||||
const response = await this.api.del(`/applications/${appId}`)
|
const response = await this.api.del(`/applications/${appId}`)
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
|
|
|
@ -29,7 +29,7 @@ describe("Internal API - Application creation, update, publish and delete", () =
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
it("Get applications without applications", async () => {
|
it("Get applications without applications", async () => {
|
||||||
await config.applications.fetch()
|
await config.applications.fetchEmptyAppList()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Get all Applications after creating an application", async () => {
|
it("Get all Applications after creating an application", async () => {
|
||||||
|
@ -38,7 +38,7 @@ describe("Internal API - Application creation, update, publish and delete", () =
|
||||||
useTemplate: false,
|
useTemplate: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
await config.applications.fetch()
|
await config.applications.fetchAllApplications()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Get application details", async () => {
|
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())
|
const app = await config.applications.create(generateApp())
|
||||||
config.applications.api.appId = app.appId
|
config.applications.api.appId = app.appId
|
||||||
|
|
||||||
await config.applications.revert(
|
await config.applications.revertUnpublished(
|
||||||
<string>app.appId,
|
<string>app.appId
|
||||||
true
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -142,7 +141,7 @@ describe("Internal API - Application creation, update, publish and delete", () =
|
||||||
)
|
)
|
||||||
|
|
||||||
// // Revert the app to published state
|
// // Revert the app to published state
|
||||||
await config.applications.revert(
|
await config.applications.revertPublished(
|
||||||
<string>app.appId
|
<string>app.appId
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue