1
0
Fork 0
mirror of synced 2024-06-02 02:25:17 +12:00

API: Screens - Add and Delete Screen

Screens API tests
- This includes adding a basic screen and deleting a screen
This commit is contained in:
Mitch-Budibase 2022-10-10 15:39:02 +01:00
parent 41ea9b9c2a
commit a620b147dd
4 changed files with 112 additions and 0 deletions

View file

@ -1,15 +1,18 @@
import ApplicationApi from "./applications"
import AuthApi from "./auth"
import InternalAPIClient from "./InternalAPIClient"
import ScreenApi from "./screens"
export default class TestConfiguration<T> {
applications: ApplicationApi
auth: AuthApi
screen: ScreenApi
context: T
constructor(apiClient: InternalAPIClient) {
this.applications = new ApplicationApi(apiClient)
this.auth = new AuthApi(apiClient)
this.screen = new ScreenApi(apiClient)
this.context = <T>{}
}

View file

@ -0,0 +1,23 @@
import { Screen } from "@budibase/types"
import { Response } from "node-fetch"
import InternalAPIClient from "./InternalAPIClient"
export default class ScreenApi {
api: InternalAPIClient
constructor(apiClient: InternalAPIClient) {
this.api = apiClient
}
async createScreen(body: any): Promise<[Response, Screen]> {
const response = await this.api.post(`/screens`, { body })
const json = await response.json()
return [response, json]
}
async deleteScreen(screenId: any, rev: any): Promise<[Response, Screen]> {
const response = await this.api.del(`/screens/${screenId}/${rev}`)
const json = await response.json()
return [response, json]
}
}

View file

@ -0,0 +1,34 @@
import generator from "../../generator"
const randomId = generator.guid()
const generateScreen = (): any => ({
showNavigation: true,
width: "Large",
name: randomId,
template: "createFromScratch",
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
},
})
export default generateScreen

View file

@ -0,0 +1,52 @@
import TestConfiguration from "../../../config/internal-api/TestConfiguration"
import { App } from "@budibase/types"
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
import generateApp from "../../../config/internal-api/fixtures/applications"
import { Screen } from "@budibase/types"
import generateScreen from "../../../config/internal-api/fixtures/screens"
describe("Internal API - /screens endpoints", () => {
const api = new InternalAPIClient()
const config = new TestConfiguration<Screen>(api)
const appConfig = new TestConfiguration<App>(api)
beforeAll(async () => {
await config.beforeAll()
})
afterAll(async () => {
await config.afterAll()
})
it("POST - Create a BASIC screen", async () => {
// Create app
const [appResponse, app] = await appConfig.applications.create(generateApp())
expect(appResponse).toHaveStatusCode(200)
expect(app._id).toBeDefined()
// Create Screen
appConfig.applications.api.appId = app.appId
const [response, screen] = await config.screen.createScreen(generateScreen())
expect(response).toHaveStatusCode(200)
expect(screen.routing.roleId).toEqual("BASIC")
})
it("DELETE - Delete a screen", async () => {
// Create app
const [appResponse, app] = await appConfig.applications.create(generateApp())
expect(appResponse).toHaveStatusCode(200)
expect(app._id).toBeDefined()
// Create Screen
appConfig.applications.api.appId = app.appId
const [screenResponse, screen] = await config.screen.createScreen(generateScreen())
expect(screenResponse).toHaveStatusCode(200)
expect(screen._id).toBeDefined()
// Delete Screen
const [response] = await config.screen.deleteScreen(screen._id, screen._rev)
expect(response).toHaveStatusCode(200)
})
})