Merge branch 'develop' into api-tests-tables
This commit is contained in:
commit
ec958f3804
|
@ -3,10 +3,12 @@ import AuthApi from "./auth"
|
|||
import InternalAPIClient from "./InternalAPIClient"
|
||||
import TablesApi from "./tables"
|
||||
import RowApi from "./rows"
|
||||
import ScreenApi from "./screens"
|
||||
|
||||
export default class TestConfiguration<T> {
|
||||
applications: ApplicationApi
|
||||
auth: AuthApi
|
||||
screen: ScreenApi
|
||||
context: T
|
||||
tables: TablesApi
|
||||
rows: RowApi
|
||||
|
@ -16,6 +18,7 @@ export default class TestConfiguration<T> {
|
|||
this.tables = new TablesApi(apiClient)
|
||||
this.rows = new RowApi(apiClient)
|
||||
this.auth = new AuthApi(apiClient)
|
||||
this.screen = new ScreenApi(apiClient)
|
||||
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 create(body: any): Promise<[Response, Screen]> {
|
||||
const response = await this.api.post(`/screens`, { body })
|
||||
const json = await response.json()
|
||||
return [response, json]
|
||||
}
|
||||
|
||||
async delete(screenId: string, rev: string): Promise<[Response, Screen]> {
|
||||
const response = await this.api.del(`/screens/${screenId}/${rev}`)
|
||||
const json = await response.json()
|
||||
return [response, json]
|
||||
}
|
||||
}
|
|
@ -2,33 +2,33 @@ 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: {},
|
||||
const generateScreen = (roleId: string): 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: roleId,
|
||||
homeScreen: false
|
||||
},
|
||||
_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
|
||||
|
|
|
@ -151,7 +151,7 @@ describe("Internal API - /applications endpoints", () => {
|
|||
|
||||
// Change/add component to the app
|
||||
const [screenResponse, screen] = await config.applications.addScreentoApp(
|
||||
generateScreen()
|
||||
generateScreen("BASIC")
|
||||
)
|
||||
expect(screenResponse).toHaveStatusCode(200)
|
||||
expect(screen._id).toBeDefined()
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
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 screen with each role type", async () => {
|
||||
// Create app
|
||||
const [appResponse, app] = await appConfig.applications.create(generateApp())
|
||||
|
||||
// Create Screen
|
||||
const roleArray = ["BASIC", "POWER", "ADMIN", "PUBLIC"]
|
||||
appConfig.applications.api.appId = app.appId
|
||||
for (let role in roleArray) {
|
||||
const [response, screen] = await config.screen.create(generateScreen(roleArray[role]))
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(screen.routing.roleId).toEqual(roleArray[role])
|
||||
}
|
||||
})
|
||||
|
||||
it("GET - Fetch screens", async () => {
|
||||
// Create app
|
||||
const [appResponse, app] = await appConfig.applications.create(generateApp())
|
||||
|
||||
// Create Screen
|
||||
appConfig.applications.api.appId = app.appId
|
||||
const [response, screen] = await config.screen.create(generateScreen("BASIC"))
|
||||
|
||||
// Check screen exists
|
||||
const [routesResponse, routes] = await appConfig.applications.getRoutes()
|
||||
expect(routesResponse).toHaveStatusCode(200)
|
||||
expect(routes.routes["/test"]).toBeTruthy()
|
||||
})
|
||||
|
||||
it("DELETE - Delete a screen", async () => {
|
||||
// Create app
|
||||
const [appResponse, app] = await appConfig.applications.create(generateApp())
|
||||
|
||||
// Create Screen
|
||||
appConfig.applications.api.appId = app.appId
|
||||
const [screenResponse, screen] = await config.screen.create(generateScreen("BASIC"))
|
||||
|
||||
// Delete Screen
|
||||
const [response] = await config.screen.delete(screen._id!, screen._rev!)
|
||||
expect(response).toHaveStatusCode(200)
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue