API: Screens - Add and Delete Screen
Screens API tests - This includes adding a basic screen and deleting a screen
This commit is contained in:
parent
41ea9b9c2a
commit
a620b147dd
|
@ -1,15 +1,18 @@
|
||||||
import ApplicationApi from "./applications"
|
import ApplicationApi from "./applications"
|
||||||
import AuthApi from "./auth"
|
import AuthApi from "./auth"
|
||||||
import InternalAPIClient from "./InternalAPIClient"
|
import InternalAPIClient from "./InternalAPIClient"
|
||||||
|
import ScreenApi from "./screens"
|
||||||
|
|
||||||
export default class TestConfiguration<T> {
|
export default class TestConfiguration<T> {
|
||||||
applications: ApplicationApi
|
applications: ApplicationApi
|
||||||
auth: AuthApi
|
auth: AuthApi
|
||||||
|
screen: ScreenApi
|
||||||
context: T
|
context: T
|
||||||
|
|
||||||
constructor(apiClient: InternalAPIClient) {
|
constructor(apiClient: InternalAPIClient) {
|
||||||
this.applications = new ApplicationApi(apiClient)
|
this.applications = new ApplicationApi(apiClient)
|
||||||
this.auth = new AuthApi(apiClient)
|
this.auth = new AuthApi(apiClient)
|
||||||
|
this.screen = new ScreenApi(apiClient)
|
||||||
this.context = <T>{}
|
this.context = <T>{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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]
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
|
@ -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)
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue