Fixing test case.
This commit is contained in:
parent
74484fc054
commit
e1dca87507
|
@ -21,7 +21,7 @@ describe("/backups", () => {
|
|||
.set(config.defaultHeaders())
|
||||
.expect(200)
|
||||
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)
|
||||
})
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { db as dbCore } from "@budibase/backend-core"
|
||||
import { budibaseTempDir } from "../../../utilities/budibaseDir"
|
||||
import { retrieveDirectory } from "../../../utilities/fileSystem/utilities"
|
||||
import { streamFile } from "../../../utilities/fileSystem"
|
||||
import { streamFile, createTempFolder } from "../../../utilities/fileSystem"
|
||||
import { ObjectStoreBuckets } from "../../../constants"
|
||||
import {
|
||||
LINK_USER_METADATA_PREFIX,
|
||||
|
@ -11,6 +11,7 @@ import {
|
|||
import { DB_EXPORT_FILE, GLOBAL_DB_EXPORT_FILE } from "./constants"
|
||||
import fs from "fs"
|
||||
import { join } from "path"
|
||||
import env from "../../../environment"
|
||||
const uuid = require("uuid/v4")
|
||||
const tar = require("tar")
|
||||
const MemoryStream = require("memorystream")
|
||||
|
@ -85,7 +86,12 @@ export async function exportApp(appId: string, config?: ExportOpts) {
|
|||
const prodAppId = dbCore.getProdAppID(appId)
|
||||
const appPath = `${prodAppId}/`
|
||||
// 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)
|
||||
if (fs.existsSync(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 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]
|
||||
}
|
||||
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]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,32 +3,32 @@ import generator from "../../generator"
|
|||
const randomId = generator.guid()
|
||||
|
||||
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
|
||||
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,
|
||||
},
|
||||
})
|
||||
|
||||
export default generateScreen
|
||||
|
|
|
@ -2,10 +2,9 @@ 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 { 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)
|
||||
|
@ -21,13 +20,17 @@ describe("Internal API - /screens endpoints", () => {
|
|||
|
||||
it("POST - Create a screen with each role type", async () => {
|
||||
// Create app
|
||||
const [appResponse, app] = await appConfig.applications.create(generateApp())
|
||||
|
||||
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]))
|
||||
const [response, screen] = await config.screen.create(
|
||||
generateScreen(roleArray[role])
|
||||
)
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(screen.routing.roleId).toEqual(roleArray[role])
|
||||
}
|
||||
|
@ -35,11 +38,15 @@ describe("Internal API - /screens endpoints", () => {
|
|||
|
||||
it("GET - Fetch screens", async () => {
|
||||
// Create app
|
||||
const [appResponse, app] = await appConfig.applications.create(generateApp())
|
||||
|
||||
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"))
|
||||
const [response, screen] = await config.screen.create(
|
||||
generateScreen("BASIC")
|
||||
)
|
||||
|
||||
// Check screen exists
|
||||
const [routesResponse, routes] = await appConfig.applications.getRoutes()
|
||||
|
@ -49,11 +56,15 @@ describe("Internal API - /screens endpoints", () => {
|
|||
|
||||
it("DELETE - Delete a screen", async () => {
|
||||
// Create app
|
||||
const [appResponse, app] = await appConfig.applications.create(generateApp())
|
||||
|
||||
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"))
|
||||
const [screenResponse, screen] = await config.screen.create(
|
||||
generateScreen("BASIC")
|
||||
)
|
||||
|
||||
// Delete Screen
|
||||
const [response] = await config.screen.delete(screen._id!, screen._rev!)
|
||||
|
|
Loading…
Reference in New Issue