Fixing test case.
This commit is contained in:
parent
74484fc054
commit
e1dca87507
|
@ -21,7 +21,7 @@ describe("/backups", () => {
|
||||||
.set(config.defaultHeaders())
|
.set(config.defaultHeaders())
|
||||||
.expect(200)
|
.expect(200)
|
||||||
expect(res.text).toBeDefined()
|
expect(res.text).toBeDefined()
|
||||||
expect(res.text.includes(`"db_name":"${config.getAppId()}"`)).toEqual(true)
|
expect(res.headers["content-type"]).toEqual("application/gzip")
|
||||||
expect(events.app.exported.mock.calls.length).toBe(1)
|
expect(events.app.exported.mock.calls.length).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { db as dbCore } from "@budibase/backend-core"
|
import { db as dbCore } from "@budibase/backend-core"
|
||||||
import { budibaseTempDir } from "../../../utilities/budibaseDir"
|
import { budibaseTempDir } from "../../../utilities/budibaseDir"
|
||||||
import { retrieveDirectory } from "../../../utilities/fileSystem/utilities"
|
import { retrieveDirectory } from "../../../utilities/fileSystem/utilities"
|
||||||
import { streamFile } from "../../../utilities/fileSystem"
|
import { streamFile, createTempFolder } from "../../../utilities/fileSystem"
|
||||||
import { ObjectStoreBuckets } from "../../../constants"
|
import { ObjectStoreBuckets } from "../../../constants"
|
||||||
import {
|
import {
|
||||||
LINK_USER_METADATA_PREFIX,
|
LINK_USER_METADATA_PREFIX,
|
||||||
|
@ -11,6 +11,7 @@ import {
|
||||||
import { DB_EXPORT_FILE, GLOBAL_DB_EXPORT_FILE } from "./constants"
|
import { DB_EXPORT_FILE, GLOBAL_DB_EXPORT_FILE } from "./constants"
|
||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
import { join } from "path"
|
import { join } from "path"
|
||||||
|
import env from "../../../environment"
|
||||||
const uuid = require("uuid/v4")
|
const uuid = require("uuid/v4")
|
||||||
const tar = require("tar")
|
const tar = require("tar")
|
||||||
const MemoryStream = require("memorystream")
|
const MemoryStream = require("memorystream")
|
||||||
|
@ -85,7 +86,12 @@ export async function exportApp(appId: string, config?: ExportOpts) {
|
||||||
const prodAppId = dbCore.getProdAppID(appId)
|
const prodAppId = dbCore.getProdAppID(appId)
|
||||||
const appPath = `${prodAppId}/`
|
const appPath = `${prodAppId}/`
|
||||||
// export bucket contents
|
// export bucket contents
|
||||||
const tmpPath = await retrieveDirectory(ObjectStoreBuckets.APPS, appPath)
|
let tmpPath
|
||||||
|
if (!env.isTest()) {
|
||||||
|
tmpPath = await retrieveDirectory(ObjectStoreBuckets.APPS, appPath)
|
||||||
|
} else {
|
||||||
|
tmpPath = createTempFolder(uuid())
|
||||||
|
}
|
||||||
const downloadedPath = join(tmpPath, appPath)
|
const downloadedPath = join(tmpPath, appPath)
|
||||||
if (fs.existsSync(downloadedPath)) {
|
if (fs.existsSync(downloadedPath)) {
|
||||||
const allFiles = fs.readdirSync(downloadedPath)
|
const allFiles = fs.readdirSync(downloadedPath)
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
import { Screen } from "@budibase/types"
|
import { Screen } from "@budibase/types"
|
||||||
import { Response } from "node-fetch"
|
import { Response } from "node-fetch"
|
||||||
import InternalAPIClient from "./InternalAPIClient"
|
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]> {
|
export default class ScreenApi {
|
||||||
const response = await this.api.del(`/screens/${screenId}/${rev}`)
|
api: InternalAPIClient
|
||||||
const json = await response.json()
|
|
||||||
return [response, json]
|
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]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,32 +3,32 @@ import generator from "../../generator"
|
||||||
const randomId = generator.guid()
|
const randomId = generator.guid()
|
||||||
|
|
||||||
const generateScreen = (roleId: string): any => ({
|
const generateScreen = (roleId: string): any => ({
|
||||||
showNavigation: true,
|
showNavigation: true,
|
||||||
width: "Large",
|
width: "Large",
|
||||||
name: randomId,
|
name: randomId,
|
||||||
template: "createFromScratch",
|
template: "createFromScratch",
|
||||||
props: {
|
props: {
|
||||||
_id: randomId,
|
_id: randomId,
|
||||||
_component:
|
_component: "@budibase/standard-components/container",
|
||||||
"@budibase/standard-components/container",
|
_styles: {
|
||||||
_styles: {
|
normal: {},
|
||||||
normal: {},
|
hover: {},
|
||||||
hover: {},
|
active: {},
|
||||||
active: {},
|
selected: {},
|
||||||
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: roleId,
|
||||||
|
homeScreen: false,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
export default generateScreen
|
export default generateScreen
|
||||||
|
|
|
@ -2,10 +2,9 @@ import TestConfiguration from "../../../config/internal-api/TestConfiguration"
|
||||||
import { App } from "@budibase/types"
|
import { App } from "@budibase/types"
|
||||||
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 { Screen } from "@budibase/types"
|
import { Screen } from "@budibase/types"
|
||||||
import generateScreen from "../../../config/internal-api/fixtures/screens"
|
import generateScreen from "../../../config/internal-api/fixtures/screens"
|
||||||
|
|
||||||
|
|
||||||
describe("Internal API - /screens endpoints", () => {
|
describe("Internal API - /screens endpoints", () => {
|
||||||
const api = new InternalAPIClient()
|
const api = new InternalAPIClient()
|
||||||
const config = new TestConfiguration<Screen>(api)
|
const config = new TestConfiguration<Screen>(api)
|
||||||
|
@ -21,13 +20,17 @@ describe("Internal API - /screens endpoints", () => {
|
||||||
|
|
||||||
it("POST - Create a screen with each role type", async () => {
|
it("POST - Create a screen with each role type", async () => {
|
||||||
// Create app
|
// Create app
|
||||||
const [appResponse, app] = await appConfig.applications.create(generateApp())
|
const [appResponse, app] = await appConfig.applications.create(
|
||||||
|
generateApp()
|
||||||
|
)
|
||||||
|
|
||||||
// Create Screen
|
// Create Screen
|
||||||
const roleArray = ["BASIC", "POWER", "ADMIN", "PUBLIC"]
|
const roleArray = ["BASIC", "POWER", "ADMIN", "PUBLIC"]
|
||||||
appConfig.applications.api.appId = app.appId
|
appConfig.applications.api.appId = app.appId
|
||||||
for (let role in roleArray) {
|
for (let role in roleArray) {
|
||||||
const [response, screen] = await config.screen.create(generateScreen(roleArray[role]))
|
const [response, screen] = await config.screen.create(
|
||||||
|
generateScreen(roleArray[role])
|
||||||
|
)
|
||||||
expect(response).toHaveStatusCode(200)
|
expect(response).toHaveStatusCode(200)
|
||||||
expect(screen.routing.roleId).toEqual(roleArray[role])
|
expect(screen.routing.roleId).toEqual(roleArray[role])
|
||||||
}
|
}
|
||||||
|
@ -35,11 +38,15 @@ describe("Internal API - /screens endpoints", () => {
|
||||||
|
|
||||||
it("GET - Fetch screens", async () => {
|
it("GET - Fetch screens", async () => {
|
||||||
// Create app
|
// Create app
|
||||||
const [appResponse, app] = await appConfig.applications.create(generateApp())
|
const [appResponse, app] = await appConfig.applications.create(
|
||||||
|
generateApp()
|
||||||
|
)
|
||||||
|
|
||||||
// Create Screen
|
// Create Screen
|
||||||
appConfig.applications.api.appId = app.appId
|
appConfig.applications.api.appId = app.appId
|
||||||
const [response, screen] = await config.screen.create(generateScreen("BASIC"))
|
const [response, screen] = await config.screen.create(
|
||||||
|
generateScreen("BASIC")
|
||||||
|
)
|
||||||
|
|
||||||
// Check screen exists
|
// Check screen exists
|
||||||
const [routesResponse, routes] = await appConfig.applications.getRoutes()
|
const [routesResponse, routes] = await appConfig.applications.getRoutes()
|
||||||
|
@ -49,11 +56,15 @@ describe("Internal API - /screens endpoints", () => {
|
||||||
|
|
||||||
it("DELETE - Delete a screen", async () => {
|
it("DELETE - Delete a screen", async () => {
|
||||||
// Create app
|
// Create app
|
||||||
const [appResponse, app] = await appConfig.applications.create(generateApp())
|
const [appResponse, app] = await appConfig.applications.create(
|
||||||
|
generateApp()
|
||||||
|
)
|
||||||
|
|
||||||
// Create Screen
|
// Create Screen
|
||||||
appConfig.applications.api.appId = app.appId
|
appConfig.applications.api.appId = app.appId
|
||||||
const [screenResponse, screen] = await config.screen.create(generateScreen("BASIC"))
|
const [screenResponse, screen] = await config.screen.create(
|
||||||
|
generateScreen("BASIC")
|
||||||
|
)
|
||||||
|
|
||||||
// Delete Screen
|
// Delete Screen
|
||||||
const [response] = await config.screen.delete(screen._id!, screen._rev!)
|
const [response] = await config.screen.delete(screen._id!, screen._rev!)
|
||||||
|
|
Loading…
Reference in New Issue