Merge branch 'budi-7010/export_controller_as_post' into budi-7010-encrypt-app-exports

This commit is contained in:
Adria Navarro 2023-06-14 14:28:26 +01:00
commit 052ecbb59a
2 changed files with 20 additions and 8 deletions

View File

@ -20,7 +20,7 @@
await downloadFile(url, { excludeRows }) await downloadFile(url, { excludeRows })
} }
export async function downloadFile(url, body) { async function downloadFile(url, body) {
try { try {
const response = await fetch(url, { const response = await fetch(url, {
method: "POST", method: "POST",
@ -51,11 +51,7 @@
notifications.error("Error exporting the app.") notifications.error("Error exporting the app.")
} }
} catch (error) { } catch (error) {
let message = "Error downloading the exported app" notifications.error(error.message || "Error downloading the exported app")
if (error.message) {
message += `: ${error.message}`
}
notifications.error("Error downloading the exported app", message)
} }
} }
</script> </script>

View File

@ -1,7 +1,9 @@
import tk from "timekeeper"
import * as setup from "./utilities" import * as setup from "./utilities"
import { events } from "@budibase/backend-core" import { events } from "@budibase/backend-core"
import sdk from "../../../sdk" import sdk from "../../../sdk"
import { checkBuilderEndpoint } from "./utilities/TestFunctions" import { checkBuilderEndpoint } from "./utilities/TestFunctions"
import { mocks } from "@budibase/backend-core/tests"
describe("/backups", () => { describe("/backups", () => {
let request = setup.getRequest() let request = setup.getRequest()
@ -16,7 +18,7 @@ describe("/backups", () => {
describe("exportAppDump", () => { describe("exportAppDump", () => {
it("should be able to export app", async () => { it("should be able to export app", async () => {
const res = await request const res = await request
.get(`/api/backups/export?appId=${config.getAppId()}&appname=test`) .post(`/api/backups/export?appId=${config.getAppId()}`)
.set(config.defaultHeaders()) .set(config.defaultHeaders())
.expect(200) .expect(200)
expect(res.headers["content-type"]).toEqual("application/gzip") expect(res.headers["content-type"]).toEqual("application/gzip")
@ -26,10 +28,24 @@ describe("/backups", () => {
it("should apply authorization to endpoint", async () => { it("should apply authorization to endpoint", async () => {
await checkBuilderEndpoint({ await checkBuilderEndpoint({
config, config,
method: "GET", method: "POST",
url: `/api/backups/export?appId=${config.getAppId()}`, url: `/api/backups/export?appId=${config.getAppId()}`,
}) })
}) })
it("should infer the app name from the app", async () => {
tk.freeze(mocks.date.MOCK_DATE)
const res = await request
.post(`/api/backups/export?appId=${config.getAppId()}`)
.set(config.defaultHeaders())
expect(res.headers["content-disposition"]).toEqual(
`attachment; filename="${
config.getApp()!.name
}-export-${mocks.date.MOCK_DATE.getTime()}.tar.gz"`
)
})
}) })
describe("calculateBackupStats", () => { describe("calculateBackupStats", () => {