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

Replace isTest check with mock for triggering app backup

This commit is contained in:
Rory Powell 2022-10-24 13:05:40 +01:00
parent e31ce3f8a9
commit 0274b6755a
6 changed files with 55 additions and 39 deletions

View file

@ -783,6 +783,7 @@
"type": "string",
"enum": [
"string",
"barcodeqr",
"longform",
"options",
"number",
@ -986,6 +987,7 @@
"type": "string",
"enum": [
"string",
"barcodeqr",
"longform",
"options",
"number",
@ -1200,6 +1202,7 @@
"type": "string",
"enum": [
"string",
"barcodeqr",
"longform",
"options",
"number",

View file

@ -579,6 +579,7 @@ components:
type: string
enum:
- string
- barcodeqr
- longform
- options
- number
@ -741,6 +742,7 @@ components:
type: string
enum:
- string
- barcodeqr
- longform
- options
- number
@ -910,6 +912,7 @@ components:
type: string
enum:
- string
- barcodeqr
- longform
- options
- number

View file

@ -20,7 +20,6 @@ import {
import { events } from "@budibase/backend-core"
import { backups } from "@budibase/pro"
import { AppBackupTrigger } from "@budibase/types"
import env from "../../../environment"
// the max time we can wait for an invalidation to complete before considering it failed
const MAX_PENDING_TIME_MS = 30 * 60000
@ -108,17 +107,10 @@ async function deployApp(deployment: any, userId: string) {
const devAppId = getDevelopmentAppID(appId)
const productionAppId = getProdAppID(appId)
// can't do this in test
if (!env.isTest()) {
// trigger backup initially
await backups.triggerAppBackup(
productionAppId,
AppBackupTrigger.PUBLISH,
{
createdBy: userId,
}
)
}
// trigger backup initially
await backups.triggerAppBackup(productionAppId, AppBackupTrigger.PUBLISH, {
createdBy: userId,
})
const config: any = {
source: devAppId,

View file

@ -1,25 +0,0 @@
const setup = require("./utilities")
const { events } = require("@budibase/backend-core")
describe("/deployments", () => {
let request = setup.getRequest()
let config = setup.getConfig()
afterAll(setup.afterAll)
beforeEach(async () => {
await config.init()
jest.clearAllMocks()
})
describe("deploy", () => {
it("should deploy the application", async () => {
await request
.post(`/api/deploy`)
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200)
expect(events.app.published.mock.calls.length).toBe(1)
})
})
})

View file

@ -0,0 +1,40 @@
const triggerAppBackupMock = jest.fn()
jest.mock("@budibase/pro", () => ({
...jest.requireActual("@budibase/pro"),
backups: {
triggerAppBackup: triggerAppBackupMock,
addAppBackupProcessors: jest.fn(),
},
}))
import setup from "./utilities"
import { events } from "@budibase/backend-core"
import { AppBackupTrigger } from "@budibase/types"
describe("/deployments", () => {
let request = setup.getRequest()
let config = setup.getConfig()
afterAll(setup.afterAll)
beforeEach(async () => {
await config.init()
jest.clearAllMocks()
})
describe("deploy", () => {
it("should deploy the application", async () => {
await request
.post(`/api/deploy`)
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200)
expect(triggerAppBackupMock).toBeCalledTimes(1)
expect(triggerAppBackupMock).toBeCalledWith(
config.prodAppId,
AppBackupTrigger.PUBLISH,
{ createdBy: config.userMetadataId }
)
expect((events.app.published as jest.Mock).mock.calls.length).toBe(1)
})
})
})

View file

@ -25,7 +25,7 @@ const newid = require("../../db/newid")
const context = require("@budibase/backend-core/context")
const { generateDevInfoID, SEPARATOR } = require("@budibase/backend-core/db")
const { encrypt } = require("@budibase/backend-core/encryption")
const { DocumentType } = require("../../db/utils")
const { DocumentType, generateUserMetadataID } = require("../../db/utils")
const GLOBAL_USER_ID = "us_uuid1"
const EMAIL = "babs@babs.com"
@ -95,7 +95,10 @@ class TestConfiguration {
// use a new id as the name to avoid name collisions
async init(appName = newid()) {
await this.globalUser()
this.user = await this.globalUser()
this.globalUserId = this.user._id
this.userMetadataId = generateUserMetadataID(this.globalUserId)
return this.createApp(appName)
}