From 34723260a83dec08931d5ed7fb152cfb87749b95 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 31 Aug 2022 14:27:22 +0100 Subject: [PATCH] Add test case for migrating navigation settings from old apps --- .../src/api/routes/tests/application.spec.js | 26 +++++++++++++++++++ .../src/api/routes/tests/data/old-app.txt | 3 +++ 2 files changed, 29 insertions(+) create mode 100644 packages/server/src/api/routes/tests/data/old-app.txt diff --git a/packages/server/src/api/routes/tests/application.spec.js b/packages/server/src/api/routes/tests/application.spec.js index 2620547298..dcfc2c6d9b 100644 --- a/packages/server/src/api/routes/tests/application.spec.js +++ b/packages/server/src/api/routes/tests/application.spec.js @@ -17,6 +17,7 @@ const { checkBuilderEndpoint, } = require("./utilities/TestFunctions") const setup = require("./utilities") +const { basicScreen, basicLayout } = setup.structures const { AppStatus } = require("../../../db/utils") const { events } = require("@budibase/backend-core") @@ -81,6 +82,31 @@ describe("/applications", () => { body: { name: "My App" }, }) }) + + it("migrates navigation settings from old apps", async () => { + const res = await request + .post("/api/applications") + .field("name", "Old App") + .field("useTemplate", "true") + .set(config.defaultHeaders()) + .attach("templateFile", "src/api/routes/tests/data/old-app.txt") + .expect("Content-Type", /json/) + .expect(200) + expect(res.body._id).toBeDefined() + expect(res.body.navigation).toBeDefined() + expect(res.body.navigation.hideLogo).toBe(true) + expect(res.body.navigation.title).toBe("Custom Title") + expect(res.body.navigation.hideLogo).toBe(true) + expect(res.body.navigation.navigation).toBe("Left") + expect(res.body.navigation.navBackground).toBe( + "var(--spectrum-global-color-blue-600)" + ) + expect(res.body.navigation.navTextColor).toBe( + "var(--spectrum-global-color-gray-50)" + ) + expect(events.app.created).toBeCalledTimes(1) + expect(events.app.fileImported).toBeCalledTimes(1) + }) }) describe("fetch", () => { diff --git a/packages/server/src/api/routes/tests/data/old-app.txt b/packages/server/src/api/routes/tests/data/old-app.txt new file mode 100644 index 0000000000..42732092e5 --- /dev/null +++ b/packages/server/src/api/routes/tests/data/old-app.txt @@ -0,0 +1,3 @@ +{"version":"1.2.9","db_type":"http","start_time":"2022-08-31T13:18:50.740Z","db_info":{"db_name":"app_dev_default_c45f987cfa274060840878557ff2f547","purge_seq":"0-g1AAAABXeJzLYWBgYMpgTmEQTM4vTc5ISXIwNDLXMwBCwxyQVB4LkGRoAFL_gSArkQGP2kSGpHqIoiwAtOgYRA","update_seq":"28-g1AAAABXeJzLYWBgYMpgTmEQTM4vTc5ISXIwNDLXMwBCwxyQVB4LkGRoAFL_gSArkQ2P2kSGpHqwIrEsALX-GGA","sizes":{"file":233890,"external":5856,"active":19326},"props":{},"doc_del_count":0,"doc_count":7,"disk_format_version":8,"compact_running":false,"cluster":{"q":2,"n":1,"w":1,"r":1},"instance_start_time":"0","host":"http://localhost:10000/db/app_dev_default_c45f987cfa274060840878557ff2f547/","auto_compaction":false,"adapter":"http"}} +{"docs":[{"_id":"_design/database","_rev":"4-afb0361e5ebb6b7e464c6c146ac3f559","views":{"by_link":{"map":"function (doc) {\n // everything in this must remain constant as its going to Pouch, no external variables\n if (doc.type === \"link\") {\n let doc1 = doc.doc1;\n let doc2 = doc.doc2;\n emit([doc1.tableId, doc1.rowId], {\n id: doc2.rowId,\n thisId: doc1.rowId,\n fieldName: doc1.fieldName,\n });\n // if linking to same table can't emit twice\n if (doc1.tableId !== doc2.tableId) {\n emit([doc2.tableId, doc2.rowId], {\n id: doc1.rowId,\n thisId: doc2.rowId,\n fieldName: doc2.fieldName,\n });\n }\n }\n }"},"screen_routes":{"map":"function(doc) {\n if (doc._id.startsWith(\"screen_\")) {\n emit(doc._id, {\n id: doc._id,\n routing: doc.routing,\n })\n }\n }"}},"indexes":{"rows":{"index":"function (doc) {\n function idx(input, prev) {\n for (let key of Object.keys(input)) {\n let idxKey = prev != null ? `${prev}.${key}` : key;\n idxKey = idxKey.replace(/ /g, \"_\");\n if (Array.isArray(input[key])) {\n for (let val of input[key]) {\n if (typeof val !== \"object\") {\n // eslint-disable-next-line no-undef\n index(idxKey, val, { store: true });\n }\n }\n }\n else if (key === \"_id\" || key === \"_rev\" || input[key] == null) {\n continue;\n }\n if (typeof input[key] === \"string\") {\n // eslint-disable-next-line no-undef\n index(idxKey, input[key].toLowerCase(), { store: true });\n }\n else if (typeof input[key] !== \"object\") {\n // eslint-disable-next-line no-undef\n index(idxKey, input[key], { store: true });\n }\n else {\n idx(input[key], idxKey);\n }\n }\n }\n if (doc._id.startsWith(\"ro_\")) {\n // eslint-disable-next-line no-undef\n index(\"default\", doc._id);\n idx(doc);\n }\n }","analyzer":"keyword"}},"_revisions":{"start":4,"ids":["afb0361e5ebb6b7e464c6c146ac3f559","d1eafe2832e6554b5d348e16d6a1b0d3","6e20795c5ba67179b478f0337a585b56","0b24e44a44af45e51e562fd124ce3007"]}},{"_id":"app_metadata","_rev":"8-9c8540f72e647e3ca7108978e862ff17","appId":"app_dev_default_c45f987cfa274060840878557ff2f547","type":"app","version":"1.0.79-alpha.7","componentLibraries":["@budibase/standard-components"],"name":"Old App","url":"/old%20app","instance":{"_id":"app_dev_default_c45f987cfa274060840878557ff2f547"},"tenantId":"default","updatedAt":"2022-08-31T13:18:05.273Z","createdAt":"2022-08-31T13:16:36.639Z","status":"development","customTheme":{"navBackground":"var(--spectrum-global-color-blue-600)","navTextColor":"var(--spectrum-global-color-gray-50)","buttonBorderRadius":"4px","primaryColor":"var(--spectrum-global-color-red-600)"},"_revisions":{"start":8,"ids":["9c8540f72e647e3ca7108978e862ff17","5c86ff8a96e1f3b4505e205f25a92656","75473d58cf92b61dbcdcd74157f9e2e1","ebc34a96a7ad678bae76d7d70880f4de","1c7397be4ef470d66bd0fd4b3fe4a002","89222c47e9d254b4885e1818cd0aac79","66bed1c391eabcea6ad3557d8ede5f27","0f1136445fd7c2cf73bb5cf41aaa19d2"]}},{"_id":"layout_private_master","_rev":"12-fa664c0538f1478b2a3695c8909a04e9","componentLibraries":["@budibase/standard-components"],"title":"Old App","favicon":"./_shared/favicon.png","stylesheets":[],"name":"Navigation Layout","props":{"_id":"4f569166-a4f3-47ea-a09e-6d218c75586f","_instanceName":"Navigation Layout","_component":"@budibase/standard-components/layout","_children":[{"_id":"7fcf11e4-6f5b-4085-8e0d-9f3d44c98967","_component":"@budibase/standard-components/screenslot","_instanceName":"Screen slot","_styles":{"normal":{"flex":"1 1 auto","display":"flex","flex-direction":"column","justify-content":"flex-start","align-items":"stretch"},"hover":{},"active":{},"selected":{}},"_children":[]}],"_styles":{"active":{},"hover":{},"normal":{},"selected":{}},"title":"Custom Title","navigation":"Left","width":"Small","links":[{"text":"Home","url":"/"}],"hideLogo":true,"hideTitle":false},"_revisions":{"start":12,"ids":["fa664c0538f1478b2a3695c8909a04e9","54b4084d5c10369ecd7a3b33d4cb7775","61e5d376e9f00d20d9905bf011680943","f222416fe5bcf0085ceb72bdc94327c1","b6d9abe1caa1a8ffec0b1e8cb7324c4b","85a347b8c8acb5ad4e31929384062e05","a7ce68d677f2fa7e9a0d54b2fb4275bb","83811e8befcdac752cdbe16cd8b33fa0","362cb9ad2c87ef9c92c58c0a41ed69d4","0a3bba6cdc98539abb3a4e98e13ef98a","d964020cc8907b37047bcd2bd1387735","156b45a34bbee17b6a4a97bfaaeb6f90"]}},{"_id":"layout_public_master","_rev":"1-c7d57c9c42e9e8f988d82f0e6cc7d32c","componentLibraries":["@budibase/standard-components"],"title":"Old App","favicon":"./_shared/favicon.png","stylesheets":[],"name":"Empty Layout","props":{"_id":"3723ffa1-f9e0-4c05-8013-98195c788ed6","_instanceName":"Empty Layout","_component":"@budibase/standard-components/layout","_children":[{"_id":"7fcf11e4-6f5b-4085-8e0d-9f3d44c98967","_component":"@budibase/standard-components/screenslot","_instanceName":"Screen slot","_styles":{"normal":{"flex":"1 1 auto","display":"flex","flex-direction":"column","justify-content":"flex-start","align-items":"stretch"},"hover":{},"active":{},"selected":{}},"_children":[]}],"_styles":{"active":{},"hover":{},"normal":{},"selected":{}},"navigation":"None","width":"Large","links":[{"text":"Home","url":"/"}]}},{"_id":"screen_c483ef802772479196a28c8a6eafe6a5","_rev":"1-db29ceb02c9c6c1ade847c8086d28a70","layoutId":"layout_private_master","props":{"_id":"cafd93b74e18b45a49a58c894d7ef29b4","_component":"@budibase/standard-components/container","_styles":{"normal":{},"hover":{},"active":{},"selected":{}},"_children":[],"_instanceName":"Home","direction":"column","hAlign":"stretch","vAlign":"top","size":"grow","gap":"M"},"routing":{"route":"/home","roleId":"BASIC"},"name":"cafd93b74e18b45a49a58c894d7ef29b4","template":"createFromScratch"},{"_id":"ta_users","_rev":"1-30a4344f056c24cf776d5736eb3c7ed5","type":"table","views":{},"name":"Users","schema":{"email":{"type":"string","constraints":{"type":"string","email":true,"length":{"maximum":""},"presence":true},"fieldName":"email","name":"email"},"firstName":{"name":"firstName","fieldName":"firstName","type":"string","constraints":{"type":"string","presence":false}},"lastName":{"name":"lastName","fieldName":"lastName","type":"string","constraints":{"type":"string","presence":false}},"roleId":{"fieldName":"roleId","name":"roleId","type":"options","constraints":{"type":"string","presence":false,"inclusion":["ADMIN","POWER","BASIC","PUBLIC"]}},"status":{"fieldName":"status","name":"status","type":"options","constraints":{"type":"string","presence":false,"inclusion":["active","inactive"]}}},"primaryDisplay":"email"}]} +{"seq":"28-g1AAAACbeJzLYWBgYMpgTmEQTM4vTc5ISXIwNDLXMwBCwxyQVCJDUv3___-zMpgTxXKBAuxJiZYGxgZG2DTgMSaPBUgyNACp_1DT2MCmGRmZWBglG2PTlwUAEaUn-w"}