Further refactoring of the tests to bring them up to date

This commit is contained in:
Dean 2024-03-04 15:11:26 +00:00
parent 5f27e3a742
commit 3c684d8cb5
3 changed files with 52 additions and 43 deletions

View File

@ -271,53 +271,70 @@ describe("/applications", () => {
await config.createApp("to-dupe") await config.createApp("to-dupe")
const sourceAppId = config.getProdAppId() const sourceAppId = config.getProdAppId()
const resp = await config.api.application.duplicateApp(sourceAppId, { const resp = await config.duplicateApp(sourceAppId, {
name: "to-dupe copy", name: "to-dupe copy",
url: "/to-dupe-copy", url: "/to-dupe-copy",
}) })
expect(resp.status).toEqual("200")
expect(events.app.duplicated).toBeCalled() expect(events.app.duplicated).toBeCalled()
expect(resp.body.duplicateAppId).toBeDefined() expect(resp.duplicateAppId).toBeDefined()
expect(resp.body.sourceAppId).toEqual(sourceAppId) expect(resp.sourceAppId).toEqual(sourceAppId)
expect(resp.body.duplicateAppId).not.toEqual(sourceAppId) expect(resp.duplicateAppId).not.toEqual(sourceAppId)
}) })
it("should reject an unknown app id with a 404", async () => { it("should reject an unknown app id with a 404", async () => {
const resp = await config.api.application.duplicateApp( let dupeError
"app_1234_not_real", try {
{ await config.duplicateApp("app_fake", {
name: "to-dupe copy", name: "to-dupe copy",
url: "/to-dupe-copy", url: "/to-dupe-copy",
} })
) } catch (err: any) {
dupeError = err
}
expect(resp.status).toEqual("404") expect(dupeError).toBeDefined()
expect(dupeError.message).toEqual("Error 404 - Source app not found")
}) })
it("should reject with a known name", async () => { it("should reject with a known name", async () => {
await config.createApp("known name") await config.createApp("known name")
const sourceAppId = config.getProdAppId() const sourceAppId = config.getProdAppId()
const resp = await config.api.application.duplicateApp(sourceAppId, {
name: "known name",
url: "/known-name",
})
expect(resp.status).toEqual("400") let dupeError
expect(resp.body.message).toEqual("App name is already in use.") try {
await config.duplicateApp(sourceAppId, {
name: "known name",
url: "/known-name",
})
} catch (err: any) {
dupeError = err
}
expect(dupeError).toBeDefined()
expect(dupeError.message).toEqual(
"Error 400 - App name is already in use."
)
}) })
it("should reject with a known url", async () => { it("should reject with a known url", async () => {
await config.createApp("known-url") await config.createApp("known-url")
const sourceAppId = config.getProdAppId() const sourceAppId = config.getProdAppId()
const resp = await config.api.application.duplicateApp(sourceAppId, {
name: "this is fine",
url: "/known-url",
})
expect(resp.status).toEqual("400") let dupeError
expect(resp.body.message).toEqual("App URL is already in use.") try {
await config.duplicateApp(sourceAppId, {
name: "this is fine",
url: "/known-url",
})
} catch (err: any) {
dupeError = err
}
expect(dupeError).toBeDefined()
expect(dupeError.message).toEqual(
"Error 400 - App URL is already in use."
)
}) })
}) })

View File

@ -575,6 +575,7 @@ export default class TestConfiguration {
async () => async () =>
(await this._req(appController.create, { (await this._req(appController.create, {
name: appName, name: appName,
url,
})) as App })) as App
) )
this.appId = this.app.appId this.appId = this.app.appId
@ -589,6 +590,16 @@ export default class TestConfiguration {
}) })
} }
async duplicateApp(appId: string, fields: object) {
return context.doInTenant(
this.tenantId!,
async () =>
await this._req(appController.duplicateApp, fields, {
appId,
})
)
}
async publish() { async publish() {
await this._req(deployController.publishApp) await this._req(deployController.publishApp)
// @ts-ignore // @ts-ignore

View File

@ -160,25 +160,6 @@ export class ApplicationAPI extends TestAPI {
} }
} }
duplicateApp = async (appId: string, fields: object): Promise<Response> => {
let headers = {
...this.config.defaultHeaders(),
[constants.Header.APP_ID]: appId,
}
const req = this.request
.post(`/api/applications/${appId}/duplicate`)
.set(headers)
.expect("Content-Type", /json/)
for (const [key, value] of Object.entries(fields)) {
req.field(key, value)
}
const response = await req
return response
}
revertClient = async (appId: string): Promise<void> => { revertClient = async (appId: string): Promise<void> => {
// While the revertClient endpoint does take an :appId parameter, it doesn't // While the revertClient endpoint does take an :appId parameter, it doesn't
// use it. It uses the appId from the context. // use it. It uses the appId from the context.