Add tests for revert endpoint
This commit is contained in:
parent
ea02929130
commit
970ba0315e
|
@ -29,7 +29,7 @@ export default class AppApi {
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async publish(): Promise<[Response, string]> {
|
async publish(): Promise<[Response, any]> {
|
||||||
const response = await this.api.post("/deploy")
|
const response = await this.api.post("/deploy")
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
return [response, json]
|
return [response, json]
|
||||||
|
@ -82,6 +82,17 @@ export default class AppApi {
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
return [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]
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
|
@ -4,6 +4,7 @@ import { db } from "@budibase/backend-core"
|
||||||
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
|
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
|
||||||
import generateApp from "../../../config/internal-api/fixtures/applications"
|
import generateApp from "../../../config/internal-api/fixtures/applications"
|
||||||
import generator from "../../../config/generator"
|
import generator from "../../../config/generator"
|
||||||
|
import generateScreen from "../../../config/internal-api/fixtures/screens"
|
||||||
|
|
||||||
describe("Internal API - /applications endpoints", () => {
|
describe("Internal API - /applications endpoints", () => {
|
||||||
const api = new InternalAPIClient()
|
const api = new InternalAPIClient()
|
||||||
|
@ -118,29 +119,57 @@ describe("Internal API - /applications endpoints", () => {
|
||||||
const [response, app] = await config.applications.create(generateApp())
|
const [response, app] = await config.applications.create(generateApp())
|
||||||
expect(response).toHaveStatusCode(200)
|
expect(response).toHaveStatusCode(200)
|
||||||
expect(app.appId).toBeDefined()
|
expect(app.appId).toBeDefined()
|
||||||
|
config.applications.api.appId = app.appId
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
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 : "", {
|
const [updateResponse, updatedApp] = await config.applications.update(app.appId ? app.appId : "", {
|
||||||
name: generator.word(),
|
name: generator.word(),
|
||||||
})
|
})
|
||||||
expect(updateResponse).toHaveStatusCode(200)
|
expect(updateResponse).toHaveStatusCode(200)
|
||||||
expect(updatedApp.name).not.toEqual(app.name)
|
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 : "")
|
const [revertResponse, revert] = await config.applications.revert(app.appId ? app.appId : "")
|
||||||
expect(revertResponse).toHaveStatusCode(200)
|
expect(revertResponse).toHaveStatusCode(200)
|
||||||
expect(revert).toEqual({
|
expect(revert).toEqual({
|
||||||
message: "App reverted successfully."
|
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 () => {
|
it("DELETE - Delete an application", async () => {
|
||||||
|
|
Loading…
Reference in New Issue