@budibase/server 1.0.27-alpha.0 → 1.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__mocks__/node-fetch.ts +0 -3
- package/builder/assets/{index.e2f56628.js → index.2ccab04a.js} +204 -208
- package/builder/assets/{index.4a13c4cb.css → index.4fb3f887.css} +1 -1
- package/builder/assets/{vendor.f9faf6ab.js → vendor.470042a4.js} +88 -88
- package/builder/index.html +3 -3
- package/coverage/clover.xml +512 -589
- package/coverage/coverage-final.json +19 -20
- package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/application.js.html +1 -1
- package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
- package/coverage/lcov-report/api/controllers/automation.js.html +10 -22
- package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
- package/coverage/lcov-report/api/controllers/component.js.html +1 -1
- package/coverage/lcov-report/api/controllers/datasource.js.html +14 -14
- package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
- package/coverage/lcov-report/api/controllers/hosting.js.html +1 -1
- package/coverage/lcov-report/api/controllers/index.html +43 -28
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
- package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
- package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
- package/coverage/lcov-report/api/controllers/{query/index.js.html → query.js.html} +27 -159
- package/coverage/lcov-report/api/controllers/role.js.html +1 -1
- package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/index.html +1 -1
- package/coverage/lcov-report/api/controllers/row/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/screen.js.html +1 -1
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/internal.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +9 -108
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
- package/coverage/lcov-report/api/controllers/webhook.js.html +6 -18
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +1 -1
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/routes/application.js.html +1 -1
- package/coverage/lcov-report/api/routes/auth.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +1 -1
- package/coverage/lcov-report/api/routes/backup.js.html +1 -1
- package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
- package/coverage/lcov-report/api/routes/component.js.html +1 -1
- package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
- package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
- package/coverage/lcov-report/api/routes/dev.js.html +1 -1
- package/coverage/lcov-report/api/routes/hosting.js.html +1 -1
- package/coverage/lcov-report/api/routes/index.html +9 -9
- package/coverage/lcov-report/api/routes/index.js.html +1 -1
- package/coverage/lcov-report/api/routes/integration.js.html +1 -1
- package/coverage/lcov-report/api/routes/layout.js.html +1 -1
- package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
- package/coverage/lcov-report/api/routes/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +98 -11
- package/coverage/lcov-report/api/routes/role.js.html +1 -1
- package/coverage/lcov-report/api/routes/routing.js.html +1 -1
- package/coverage/lcov-report/api/routes/row.js.html +1 -1
- package/coverage/lcov-report/api/routes/screen.js.html +1 -1
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/static.js.html +1 -1
- package/coverage/lcov-report/api/routes/table.js.html +1 -1
- package/coverage/lcov-report/api/routes/templates.js.html +1 -1
- package/coverage/lcov-report/api/routes/user.js.html +2 -32
- package/coverage/lcov-report/api/routes/view.js.html +1 -1
- package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +1 -1
- package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
- package/coverage/lcov-report/automations/bullboard.js.html +1 -1
- package/coverage/lcov-report/automations/index.html +20 -20
- package/coverage/lcov-report/automations/index.js.html +1 -1
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/createRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +1 -1
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -5
- package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
- package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
- package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
- package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/triggers.js.html +1 -1
- package/coverage/lcov-report/automations/utils.js.html +11 -44
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +22 -22
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +1 -1
- package/coverage/lcov-report/db/client.js.html +18 -18
- package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +15 -15
- package/coverage/lcov-report/db/index.js.html +3 -3
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
- package/coverage/lcov-report/db/newid.js.html +4 -4
- package/coverage/lcov-report/db/utils.js.html +64 -91
- package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +1 -1
- package/coverage/lcov-report/events/utils.js.html +1 -1
- package/coverage/lcov-report/index.html +60 -75
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
- package/coverage/lcov-report/middleware/authorized.js.html +2 -2
- package/coverage/lcov-report/middleware/builder.js.html +1 -1
- package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
- package/coverage/lcov-report/middleware/index.html +1 -1
- package/coverage/lcov-report/middleware/joi-validator.js.html +3 -3
- package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/usageQuota.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +1 -1
- package/coverage/lcov-report/threads/automation.js.html +1 -1
- package/coverage/lcov-report/threads/index.html +19 -19
- package/coverage/lcov-report/threads/index.js.html +1 -1
- package/coverage/lcov-report/threads/query.js.html +12 -63
- package/coverage/lcov-report/threads/utils.js.html +1 -1
- package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
- package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
- package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
- package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
- package/coverage/lcov-report/utilities/global.js.html +1 -1
- package/coverage/lcov-report/utilities/index.html +19 -19
- package/coverage/lcov-report/utilities/index.js.html +33 -66
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +1 -1
- package/coverage/lcov-report/utilities/queue/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
- package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
- package/coverage/lcov-report/utilities/security.js.html +2 -2
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
- package/coverage/lcov.info +851 -969
- package/dist/api/controllers/automation.js +5 -7
- package/dist/api/controllers/{query/index.js → query.js} +6 -42
- package/dist/api/controllers/user.js +1 -37
- package/dist/api/controllers/webhook.js +0 -4
- package/dist/api/routes/query.js +32 -2
- package/dist/api/routes/user.js +1 -3
- package/dist/automations/steps/outgoingWebhook.js +3 -2
- package/dist/automations/utils.js +0 -10
- package/dist/db/utils.js +0 -8
- package/dist/definitions/datasource.js +1 -6
- package/dist/integrations/rest.js +117 -207
- package/dist/package.json +4 -10
- package/dist/threads/query.js +2 -14
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/index.js +0 -10
- package/package.json +5 -11
- package/src/api/controllers/automation.js +4 -8
- package/src/api/controllers/{query/index.js → query.js} +6 -50
- package/src/api/controllers/user.js +0 -33
- package/src/api/controllers/webhook.js +0 -4
- package/src/api/routes/query.js +34 -5
- package/src/api/routes/user.js +0 -10
- package/src/automations/steps/outgoingWebhook.js +3 -2
- package/src/automations/utils.js +0 -11
- package/src/db/utils.js +0 -9
- package/src/definitions/common.ts +16 -2
- package/src/definitions/datasource.ts +1 -73
- package/src/integrations/base/IntegrationBase.ts +4 -4
- package/src/integrations/oracle.ts +1 -1
- package/src/integrations/rest.ts +137 -227
- package/src/integrations/tests/rest.spec.js +19 -167
- package/src/threads/query.js +2 -19
- package/src/utilities/index.js +0 -11
- package/builder/assets/bb-spaceship.8f6e81e1.svg +0 -227
- package/coverage/lcov-report/api/controllers/query/index.html +0 -126
- package/coverage/lcov-report/api/controllers/query/validation.js.html +0 -203
- package/dist/api/controllers/query/import/index.js +0 -79
- package/dist/api/controllers/query/import/sources/base/index.js +0 -63
- package/dist/api/controllers/query/import/sources/base/openapi.js +0 -42
- package/dist/api/controllers/query/import/sources/curl.js +0 -90
- package/dist/api/controllers/query/import/sources/openapi2.js +0 -139
- package/dist/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.json +0 -253
- package/dist/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.json +0 -1054
- package/dist/api/controllers/query/validation.js +0 -37
- package/src/api/controllers/query/import/index.ts +0 -85
- package/src/api/controllers/query/import/sources/base/index.ts +0 -85
- package/src/api/controllers/query/import/sources/base/openapi.ts +0 -24
- package/src/api/controllers/query/import/sources/curl.ts +0 -94
- package/src/api/controllers/query/import/sources/openapi2.ts +0 -159
- package/src/api/controllers/query/import/sources/tests/curl/curl.spec.js +0 -104
- package/src/api/controllers/query/import/sources/tests/curl/data/delete.txt +0 -1
- package/src/api/controllers/query/import/sources/tests/curl/data/empty-body.txt +0 -2
- package/src/api/controllers/query/import/sources/tests/curl/data/get.txt +0 -1
- package/src/api/controllers/query/import/sources/tests/curl/data/headers.txt +0 -3
- package/src/api/controllers/query/import/sources/tests/curl/data/patch.txt +0 -2
- package/src/api/controllers/query/import/sources/tests/curl/data/path.txt +0 -1
- package/src/api/controllers/query/import/sources/tests/curl/data/post.txt +0 -2
- package/src/api/controllers/query/import/sources/tests/curl/data/put.txt +0 -2
- package/src/api/controllers/query/import/sources/tests/curl/data/query.txt +0 -1
- package/src/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.json +0 -253
- package/src/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.yaml +0 -160
- package/src/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.json +0 -1054
- package/src/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.yaml +0 -711
- package/src/api/controllers/query/import/sources/tests/openapi2/openapi2.spec.js +0 -239
- package/src/api/controllers/query/import/tests/index.spec.js +0 -115
- package/src/api/controllers/query/validation.js +0 -41
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
const { OpenAPI2 } = require("../../openapi2")
|
|
2
|
-
const fs = require("fs")
|
|
3
|
-
const path = require('path')
|
|
4
|
-
|
|
5
|
-
const getData = (file, extension) => {
|
|
6
|
-
return fs.readFileSync(path.join(__dirname, `./data/${file}/${file}.${extension}`), "utf8")
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
describe("OpenAPI2 Import", () => {
|
|
10
|
-
let openapi2
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
openapi2 = new OpenAPI2()
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
it("validates unsupported data", async () => {
|
|
17
|
-
let data
|
|
18
|
-
let supported
|
|
19
|
-
|
|
20
|
-
// non json / yaml
|
|
21
|
-
data = "curl http://example.com"
|
|
22
|
-
supported = await openapi2.isSupported(data)
|
|
23
|
-
expect(supported).toBe(false)
|
|
24
|
-
|
|
25
|
-
// Empty
|
|
26
|
-
data = ""
|
|
27
|
-
supported = await openapi2.isSupported(data)
|
|
28
|
-
expect(supported).toBe(false)
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
const init = async (file, extension) => {
|
|
32
|
-
await openapi2.isSupported(getData(file, extension))
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const runTests = async (filename, test, assertions) => {
|
|
36
|
-
for (let extension of ["json", "yaml"]) {
|
|
37
|
-
await test(filename, extension, assertions)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const testImportInfo = async (file, extension) => {
|
|
42
|
-
await init(file, extension)
|
|
43
|
-
const info = await openapi2.getInfo()
|
|
44
|
-
expect(info.url).toBe("https://petstore.swagger.io/v2")
|
|
45
|
-
expect(info.name).toBe("Swagger Petstore")
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
it("returns import info", async () => {
|
|
49
|
-
await runTests("petstore", testImportInfo)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
describe("Returns queries", () => {
|
|
53
|
-
const indexQueries = (queries) => {
|
|
54
|
-
return queries.reduce((acc, query) => {
|
|
55
|
-
acc[query.name] = query
|
|
56
|
-
return acc
|
|
57
|
-
}, {})
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const getQueries = async (file, extension) => {
|
|
61
|
-
await init(file, extension)
|
|
62
|
-
const queries = await openapi2.getQueries()
|
|
63
|
-
expect(queries.length).toBe(6)
|
|
64
|
-
return indexQueries(queries)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const testVerb = async (file, extension, assertions) => {
|
|
68
|
-
const queries = await getQueries(file, extension)
|
|
69
|
-
for (let [operationId, method] of Object.entries(assertions)) {
|
|
70
|
-
expect(queries[operationId].queryVerb).toBe(method)
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
it("populates verb", async () => {
|
|
75
|
-
const assertions = {
|
|
76
|
-
"createEntity" : "create",
|
|
77
|
-
"getEntities" : "read",
|
|
78
|
-
"getEntity" : "read",
|
|
79
|
-
"updateEntity" : "update",
|
|
80
|
-
"patchEntity" : "patch",
|
|
81
|
-
"deleteEntity" : "delete"
|
|
82
|
-
}
|
|
83
|
-
await runTests("crud", testVerb, assertions)
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
const testPath = async (file, extension, assertions) => {
|
|
87
|
-
const queries = await getQueries(file, extension)
|
|
88
|
-
for (let [operationId, urlPath] of Object.entries(assertions)) {
|
|
89
|
-
expect(queries[operationId].fields.path).toBe(urlPath)
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
it("populates path", async () => {
|
|
94
|
-
const assertions = {
|
|
95
|
-
"createEntity" : "entities",
|
|
96
|
-
"getEntities" : "entities",
|
|
97
|
-
"getEntity" : "entities/{{entityId}}",
|
|
98
|
-
"updateEntity" : "entities/{{entityId}}",
|
|
99
|
-
"patchEntity" : "entities/{{entityId}}",
|
|
100
|
-
"deleteEntity" : "entities/{{entityId}}"
|
|
101
|
-
}
|
|
102
|
-
await runTests("crud", testPath, assertions)
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
const testHeaders = async (file, extension, assertions) => {
|
|
106
|
-
const queries = await getQueries(file, extension)
|
|
107
|
-
for (let [operationId, headers] of Object.entries(assertions)) {
|
|
108
|
-
expect(queries[operationId].fields.headers).toStrictEqual(headers)
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const contentTypeHeader = {
|
|
113
|
-
"Content-Type" : "application/json",
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
it("populates headers", async () => {
|
|
117
|
-
const assertions = {
|
|
118
|
-
"createEntity" : {
|
|
119
|
-
...contentTypeHeader
|
|
120
|
-
},
|
|
121
|
-
"getEntities" : {
|
|
122
|
-
},
|
|
123
|
-
"getEntity" : {
|
|
124
|
-
},
|
|
125
|
-
"updateEntity" : {
|
|
126
|
-
...contentTypeHeader
|
|
127
|
-
},
|
|
128
|
-
"patchEntity" : {
|
|
129
|
-
...contentTypeHeader
|
|
130
|
-
},
|
|
131
|
-
"deleteEntity" : {
|
|
132
|
-
"x-api-key" : "{{x-api-key}}",
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
await runTests("crud", testHeaders, assertions)
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
const testQuery = async (file, extension, assertions) => {
|
|
140
|
-
const queries = await getQueries(file, extension)
|
|
141
|
-
for (let [operationId, queryString] of Object.entries(assertions)) {
|
|
142
|
-
expect(queries[operationId].fields.queryString).toStrictEqual(queryString)
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
it("populates query", async () => {
|
|
147
|
-
const assertions = {
|
|
148
|
-
"createEntity" : "",
|
|
149
|
-
"getEntities" : "page={{page}}&size={{size}}",
|
|
150
|
-
"getEntity" : "",
|
|
151
|
-
"updateEntity" : "",
|
|
152
|
-
"patchEntity" : "",
|
|
153
|
-
"deleteEntity" : ""
|
|
154
|
-
}
|
|
155
|
-
await runTests("crud", testQuery, assertions)
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
const testParameters = async (file, extension, assertions) => {
|
|
159
|
-
const queries = await getQueries(file, extension)
|
|
160
|
-
for (let [operationId, parameters] of Object.entries(assertions)) {
|
|
161
|
-
expect(queries[operationId].parameters).toStrictEqual(parameters)
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
it("populates parameters", async () => {
|
|
166
|
-
const assertions = {
|
|
167
|
-
"createEntity" : [],
|
|
168
|
-
"getEntities" : [
|
|
169
|
-
{
|
|
170
|
-
"name" : "page",
|
|
171
|
-
"default" : "",
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
"name" : "size",
|
|
175
|
-
"default" : "",
|
|
176
|
-
}
|
|
177
|
-
],
|
|
178
|
-
"getEntity" : [
|
|
179
|
-
{
|
|
180
|
-
"name" : "entityId",
|
|
181
|
-
"default" : "",
|
|
182
|
-
}
|
|
183
|
-
],
|
|
184
|
-
"updateEntity" : [
|
|
185
|
-
{
|
|
186
|
-
"name" : "entityId",
|
|
187
|
-
"default" : "",
|
|
188
|
-
}
|
|
189
|
-
],
|
|
190
|
-
"patchEntity" : [
|
|
191
|
-
{
|
|
192
|
-
"name" : "entityId",
|
|
193
|
-
"default" : "",
|
|
194
|
-
}
|
|
195
|
-
],
|
|
196
|
-
"deleteEntity" : [
|
|
197
|
-
{
|
|
198
|
-
"name" : "entityId",
|
|
199
|
-
"default" : "",
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
"name" : "x-api-key",
|
|
203
|
-
"default" : "",
|
|
204
|
-
}
|
|
205
|
-
]
|
|
206
|
-
}
|
|
207
|
-
await runTests("crud", testParameters, assertions)
|
|
208
|
-
})
|
|
209
|
-
|
|
210
|
-
const testBody = async (file, extension, assertions) => {
|
|
211
|
-
const queries = await getQueries(file, extension)
|
|
212
|
-
for (let [operationId, body] of Object.entries(assertions)) {
|
|
213
|
-
expect(queries[operationId].fields.requestBody).toStrictEqual(JSON.stringify(body, null, 2))
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
it("populates body", async () => {
|
|
217
|
-
const assertions = {
|
|
218
|
-
"createEntity" : {
|
|
219
|
-
"name" : "name",
|
|
220
|
-
"type" : "type",
|
|
221
|
-
},
|
|
222
|
-
"getEntities" : undefined,
|
|
223
|
-
"getEntity" : undefined,
|
|
224
|
-
"updateEntity" : {
|
|
225
|
-
"id": 1,
|
|
226
|
-
"name" : "name",
|
|
227
|
-
"type" : "type",
|
|
228
|
-
},
|
|
229
|
-
"patchEntity" : {
|
|
230
|
-
"id": 1,
|
|
231
|
-
"name" : "name",
|
|
232
|
-
"type" : "type",
|
|
233
|
-
},
|
|
234
|
-
"deleteEntity" : undefined
|
|
235
|
-
}
|
|
236
|
-
await runTests("crud", testBody, assertions)
|
|
237
|
-
})
|
|
238
|
-
})
|
|
239
|
-
})
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
const bulkDocs = jest.fn()
|
|
3
|
-
const db = jest.fn(() => {
|
|
4
|
-
return {
|
|
5
|
-
bulkDocs
|
|
6
|
-
}
|
|
7
|
-
})
|
|
8
|
-
jest.mock("../../../../../db", () => db)
|
|
9
|
-
|
|
10
|
-
const { RestImporter } = require("../index")
|
|
11
|
-
|
|
12
|
-
const fs = require("fs")
|
|
13
|
-
const path = require('path')
|
|
14
|
-
|
|
15
|
-
const getData = (file) => {
|
|
16
|
-
return fs.readFileSync(path.join(__dirname, `../sources/tests/${file}`), "utf8")
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// openapi2 (swagger)
|
|
20
|
-
const oapi2CrudJson = getData("openapi2/data/crud/crud.json")
|
|
21
|
-
const oapi2CrudYaml = getData("openapi2/data/crud/crud.json")
|
|
22
|
-
const oapi2PetstoreJson = getData("openapi2/data/petstore/petstore.json")
|
|
23
|
-
const oapi2PetstoreYaml = getData("openapi2/data/petstore/petstore.json")
|
|
24
|
-
|
|
25
|
-
// curl
|
|
26
|
-
const curl = getData("curl/data/post.txt")
|
|
27
|
-
|
|
28
|
-
const datasets = {
|
|
29
|
-
oapi2CrudJson,
|
|
30
|
-
oapi2CrudYaml,
|
|
31
|
-
oapi2PetstoreJson,
|
|
32
|
-
oapi2PetstoreYaml,
|
|
33
|
-
curl
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
describe("Rest Importer", () => {
|
|
37
|
-
let restImporter
|
|
38
|
-
|
|
39
|
-
const init = async (data) => {
|
|
40
|
-
restImporter = new RestImporter(data)
|
|
41
|
-
await restImporter.init()
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const runTest = async (test, assertions) => {
|
|
45
|
-
for (let [key, data] of Object.entries(datasets)) {
|
|
46
|
-
await test(key, data, assertions)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const testGetInfo = async (key, data, assertions) => {
|
|
51
|
-
await init(data)
|
|
52
|
-
const info = await restImporter.getInfo()
|
|
53
|
-
expect(info.name).toBe(assertions[key].name)
|
|
54
|
-
expect(info.url).toBe(assertions[key].url)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
it("gets info", async () => {
|
|
58
|
-
const assertions = {
|
|
59
|
-
"oapi2CrudJson" : {
|
|
60
|
-
name: "CRUD",
|
|
61
|
-
url: "http://example.com"
|
|
62
|
-
},
|
|
63
|
-
"oapi2CrudYaml" : {
|
|
64
|
-
name: "CRUD",
|
|
65
|
-
url: "http://example.com"
|
|
66
|
-
},
|
|
67
|
-
"oapi2PetstoreJson" : {
|
|
68
|
-
name: "Swagger Petstore",
|
|
69
|
-
url: "https://petstore.swagger.io/v2"
|
|
70
|
-
},
|
|
71
|
-
"oapi2PetstoreYaml" :{
|
|
72
|
-
name: "Swagger Petstore",
|
|
73
|
-
url: "https://petstore.swagger.io/v2"
|
|
74
|
-
},
|
|
75
|
-
"curl": {
|
|
76
|
-
name: "example.com",
|
|
77
|
-
url: "http://example.com"
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
await runTest(testGetInfo, assertions)
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
const testImportQueries = async (key, data, assertions) => {
|
|
84
|
-
await init(data)
|
|
85
|
-
bulkDocs.mockReturnValue([])
|
|
86
|
-
const importResult = await restImporter.importQueries("appId", "datasourceId")
|
|
87
|
-
expect(importResult.errorQueries.length).toBe(0)
|
|
88
|
-
expect(importResult.queries.length).toBe(assertions[key].count)
|
|
89
|
-
expect(bulkDocs).toHaveBeenCalledTimes(1)
|
|
90
|
-
jest.clearAllMocks()
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
it("imports queries", async () => {
|
|
94
|
-
// simple sanity assertions that the whole dataset
|
|
95
|
-
// makes it through the importer
|
|
96
|
-
const assertions = {
|
|
97
|
-
"oapi2CrudJson" : {
|
|
98
|
-
count: 6,
|
|
99
|
-
},
|
|
100
|
-
"oapi2CrudYaml" :{
|
|
101
|
-
count: 6,
|
|
102
|
-
},
|
|
103
|
-
"oapi2PetstoreJson" : {
|
|
104
|
-
count: 20,
|
|
105
|
-
},
|
|
106
|
-
"oapi2PetstoreYaml" :{
|
|
107
|
-
count: 20,
|
|
108
|
-
},
|
|
109
|
-
"curl": {
|
|
110
|
-
count: 1
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
await runTest(testImportQueries, assertions)
|
|
114
|
-
})
|
|
115
|
-
})
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const joiValidator = require("../../../middleware/joi-validator")
|
|
2
|
-
const Joi = require("joi")
|
|
3
|
-
|
|
4
|
-
exports.queryValidation = () => {
|
|
5
|
-
return Joi.object({
|
|
6
|
-
_id: Joi.string(),
|
|
7
|
-
_rev: Joi.string(),
|
|
8
|
-
name: Joi.string().required(),
|
|
9
|
-
fields: Joi.object().required(),
|
|
10
|
-
datasourceId: Joi.string().required(),
|
|
11
|
-
readable: Joi.boolean(),
|
|
12
|
-
parameters: Joi.array().items(
|
|
13
|
-
Joi.object({
|
|
14
|
-
name: Joi.string(),
|
|
15
|
-
default: Joi.string().allow(""),
|
|
16
|
-
})
|
|
17
|
-
),
|
|
18
|
-
queryVerb: Joi.string().allow().required(),
|
|
19
|
-
extra: Joi.object().optional(),
|
|
20
|
-
schema: Joi.object({}).required().unknown(true),
|
|
21
|
-
transformer: Joi.string().optional(),
|
|
22
|
-
flags: Joi.object().optional(),
|
|
23
|
-
})
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
exports.generateQueryValidation = () => {
|
|
27
|
-
// prettier-ignore
|
|
28
|
-
return joiValidator.body(exports.queryValidation())
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
exports.generateQueryPreviewValidation = () => {
|
|
32
|
-
// prettier-ignore
|
|
33
|
-
return joiValidator.body(Joi.object({
|
|
34
|
-
fields: Joi.object().required(),
|
|
35
|
-
queryVerb: Joi.string().allow().required(),
|
|
36
|
-
extra: Joi.object().optional(),
|
|
37
|
-
datasourceId: Joi.string().required(),
|
|
38
|
-
transformer: Joi.string().optional(),
|
|
39
|
-
parameters: Joi.object({}).required().unknown(true)
|
|
40
|
-
}))
|
|
41
|
-
}
|