From 7bc6dfbdd347ea7030e46cf96217c5e2ddf34396 Mon Sep 17 00:00:00 2001 From: michael shanks Date: Thu, 18 Jul 2019 08:05:16 +0100 Subject: [PATCH] all tests passing again after refactor for serving UI --- .../appPackages/master/appDefinition.json | 6 ++ packages/server/appPackages/master/main.js | 16 ++++ .../appPackages/testApp/appDefinition.json | 87 +++++++++++++++++- .../appPackages/testApp/dist/package.tar.gz | Bin 1053 -> 1248 bytes .../server/appPackages/testApp/plugins.js | 9 +- packages/server/package.json | 2 +- packages/server/tests/createNewApp.js | 12 ++- .../server/utilities/masterAppInternal.js | 9 +- 8 files changed, 133 insertions(+), 8 deletions(-) diff --git a/packages/server/appPackages/master/appDefinition.json b/packages/server/appPackages/master/appDefinition.json index e9399f759a..d5d0748c8c 100644 --- a/packages/server/appPackages/master/appDefinition.json +++ b/packages/server/appPackages/master/appDefinition.json @@ -502,6 +502,12 @@ "behaviourSource": "main", "behaviourName": "createNewUser", "initialOptions": {} + }, + "set_default_version": { + "name": "set_default_version", + "behaviourSource": "main", + "behaviourName": "setDefaultVersion", + "initialOptions": {} } }, "triggers": [ diff --git a/packages/server/appPackages/master/main.js b/packages/server/appPackages/master/main.js index ac0ff8a736..62403902f6 100644 --- a/packages/server/appPackages/master/main.js +++ b/packages/server/appPackages/master/main.js @@ -86,6 +86,22 @@ module.exports = (context) => { authUser.accessLevels = [instance.version.defaultAccessLevel]; await instanceApis.authApi.createUser(authUser); + }, + + setDefaultVersion : async ({apis, version}) => { + const appKey = $(version.key, [ + splitKey, + take(2), + joinKey + ]); + + const application = await apis.recordApi.load(appKey); + + if(application.defaultVersion.key) return; + + application.defaultVersion = version; + + await apis.recordApi.save(application); } }); diff --git a/packages/server/appPackages/testApp/appDefinition.json b/packages/server/appPackages/testApp/appDefinition.json index a303f152d4..58f80233fb 100644 --- a/packages/server/appPackages/testApp/appDefinition.json +++ b/packages/server/appPackages/testApp/appDefinition.json @@ -1 +1,86 @@ -{"hierarchy":{"name":"root","type":"root","children":[{"name":"customer","type":"record","fields":[{"name":"name","type":"string","typeOptions":{"maxLength":1000,"values":null,"allowDeclaredValuesOnly":false},"label":"name","getInitialValue":"default","getUndefinedValue":"default"}],"children":[{"name":"invoiceyooo","type":"record","fields":[{"name":"amount","type":"number","typeOptions":{"minValue":99999999999,"maxValue":99999999999,"decimalPlaces":2},"label":"amount","getInitialValue":"default","getUndefinedValue":"default"}],"children":[],"validationRules":[],"nodeId":2,"indexes":[],"allidsShardFactor":1,"collectionName":"invoices","isSingle":false}],"validationRules":[],"nodeId":1,"indexes":[],"allidsShardFactor":64,"collectionName":"customers","isSingle":false}],"pathMaps":[],"indexes":[],"nodeId":0},"triggers":[{"actionName":"output_to_file","eventName":"authApi:createUser:onComplete","optionsCreator":"return { filename:'tempaccess' + context.user.name, content:context.result.tempCode };","condition":"!context.password"},{"actionName":"output_to_file","eventName":"authApi:createTemporaryAccess:onComplete","optionsCreator":"return { filename:'tempaccess' + context.userName, content:context.result };","condition":""}],"actions":{"output_to_file":[{"name":"output_to_file","behaviourSource":"main","behaviourName":"outputToFile","initialOptions":{}}]}} \ No newline at end of file +{ + "hierarchy": { + "name": "root", + "type": "root", + "children": [ + { + "name": "customer", + "type": "record", + "fields": [ + { + "name": "name", + "type": "string", + "typeOptions": { + "maxLength": 1000, + "values": null, + "allowDeclaredValuesOnly": false + }, + "label": "name", + "getInitialValue": "default", + "getUndefinedValue": "default" + } + ], + "children": [ + { + "name": "invoiceyooo", + "type": "record", + "fields": [ + { + "name": "amount", + "type": "number", + "typeOptions": { + "minValue": 99999999999, + "maxValue": 99999999999, + "decimalPlaces": 2 + }, + "label": "amount", + "getInitialValue": "default", + "getUndefinedValue": "default" + } + ], + "children": [], + "validationRules": [], + "nodeId": 2, + "indexes": [], + "allidsShardFactor": 1, + "collectionName": "invoices", + "isSingle": false + } + ], + "validationRules": [], + "nodeId": 1, + "indexes": [], + "allidsShardFactor": 64, + "collectionName": "customers", + "isSingle": false + } + ], + "pathMaps": [], + "indexes": [], + "nodeId": 0 + }, + "triggers": [ + { + "actionName": "output_to_file", + "eventName": "authApi:createUser:onComplete", + "optionsCreator": "return { filename:'tempaccess' + context.user.name, content:context.result.tempCode };", + "condition": "!context.password" + }, + { + "actionName": "output_to_file", + "eventName": "authApi:createTemporaryAccess:onComplete", + "optionsCreator": "return { filename:'tempaccess' + context.userName, content:context.result };", + "condition": "" + } + ], + "actions": { + "output_to_file": + { + "name": "output_to_file", + "behaviourSource": "main", + "behaviourName": "outputToFile", + "initialOptions": {} + } + + } +} \ No newline at end of file diff --git a/packages/server/appPackages/testApp/dist/package.tar.gz b/packages/server/appPackages/testApp/dist/package.tar.gz index 8cd74900b66488d09325bde70dea1c63d4b0b69f..1115b0e5a8d825e19ae8f7c57e693010226add4e 100644 GIT binary patch literal 1248 zcmV<61Rwh!iwFP!000003hfwaZ`(FBp9}OqaKeB(m}g5qHy0gHq$p5qYm27cmm)|R z>DgvMks3+a2@L)BK1!CO%g)gpJN$w`Hs5{nS)GIX2iJ8+qY<%Bgz7W<;`N8_Xgu@= zUXQr$xbKe1!SDfWJBYQR3QhT5IaTNWB|v>2v_9pq0IoYe`{<+Pm$RLHbuQet!zV-1ExRO_YHTPL@oq@wDAWD}@J z0)n1#AX1Tl>GWe&cxFzEv^EL~)^?3zL3s?8S;U;z z(Ufz!d<8zI3WC2<+INE6Fi$DhP^M3+=5cxke5-FWFmG(%Ql1L7bOB6h%uN&NCmd|p z=W8p9#6{ZV^2pTxiu&CjHl@4tT!ktDWsu{Ma}V&J`sm!<>D)m z?5Km3CS)QH-LIF>AT6t#Ytshcvyk%locd`Y_3BjB!btfx#j(Tn>z7DQe!VhDjVd3U zRP$IYnHmz?hT)Qg0sj#5)a^QrT~*!$HX>C_dP#5L!j5BsKAuw*yr#a9%C>IJw#{Ar zwp_5fR*p;``l9e(xQEX0)Je@LL7;p~mSi5u0S2 z<0st3CQ=+pTt#s`E-=ZgfsZU%8YG-BCRT#1h!t-q#pIdYJF`vh8Tko!Heul0bnJrH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3h?7y1zI5yQ~ ({ main: { - outputToFile : ({filename, content}) => { - fs.writeFile(`./tests/.data/${filename}`, content, {encoding:"utf8"}); + outputToFile : async ({filename, content}) => { + await new Promise((resolve,reject) => { + fs.writeFile(`./tests/.data/${filename}`, content, {encoding:"utf8"}, err => { + if(err) reject(); + else resolve(err); + }); + }); } } }) \ No newline at end of file diff --git a/packages/server/package.json b/packages/server/package.json index 834c3f0779..0ca5ad75c2 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -17,8 +17,8 @@ "budibase-core": "file:../core/dist", "koa": "^2.7.0", "koa-body": "^4.1.0", - "koa-session": "^5.12.0", "koa-send": "^5.0.0", + "koa-session": "^5.12.0", "koa-static": "^5.0.0", "ncp": "^2.0.0", "rimraf": "^2.6.3", diff --git a/packages/server/tests/createNewApp.js b/packages/server/tests/createNewApp.js index ec76affe0b..82e659070c 100644 --- a/packages/server/tests/createNewApp.js +++ b/packages/server/tests/createNewApp.js @@ -1,7 +1,8 @@ const statusCodes = require("../utilities/statusCodes"); const constructHierarchy = require("../utilities/constructHierarchy"); const { readFile } = require("../utilities/fsawait"); -const {getRecordApi, getAuthApi} = require("budibase-core"); +const { hierarchy } = require("budibase-core"); +const { take } = require("lodash/fp"); const masterAppDefinition = constructHierarchy( require("../appPackages/master/appDefinition.json")); const {getApisWithFullAccess} = require("../utilities/budibaseApi"); @@ -57,6 +58,15 @@ module.exports = (app) => { .set("cookie", app.credentials.masterOwner.cookie) .expect(statusCodes.OK); + const savedAppResponse = await app.get(`/_master/api/record/${newAppKey}`) + .set("cookie", app.credentials.masterOwner.cookie); + + const savedApp = savedAppResponse.body; + savedApp.defaultVersion = version1 + await app.post(`/_master/api/record/${newAppKey}`, savedApp) + .set("cookie", app.credentials.masterOwner.cookie) + .expect(statusCodes.OK); + app.apps.testApp1.version1 = version1; }); diff --git a/packages/server/utilities/masterAppInternal.js b/packages/server/utilities/masterAppInternal.js index c77d632444..d19954039a 100644 --- a/packages/server/utilities/masterAppInternal.js +++ b/packages/server/utilities/masterAppInternal.js @@ -6,7 +6,7 @@ const { const getDatastore = require("./datastore"); const getDatabaseManager = require("./databaseManager"); const {$, splitKey} = require("budibase-core").common; -const { keyBy, last } = require("lodash/fp"); +const { keyBy, last, filter } = require("lodash/fp"); const { masterAppPackage, applictionVersionPackage, @@ -30,10 +30,13 @@ module.exports = async (context) => { const bb = await getMasterApisWithFullAccess(context); let applications; - const loadApplications = async () => - applications = $(await bb.indexApi.listItems("/all_applications"), [ + const loadApplications = async () => { + const apps = await bb.indexApi.listItems("/all_applications"); + applications = $(apps, [ + filter(a => !!a.defaultVersion.key), keyBy("name") ]); + } await loadApplications(); const getInstanceDatastore = (instanceDatastoreConfig) =>