@budibase/server 2.4.40 → 2.4.42-alpha.0

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.
Files changed (75) hide show
  1. package/__mocks__/node-fetch.ts +6 -1
  2. package/builder/assets/index.3cb1022d.css +6 -0
  3. package/builder/assets/{index.07ed2ead.js → index.4b6c8c0e.js} +384 -383
  4. package/builder/index.html +7 -7
  5. package/dist/api/controllers/application.js +28 -24
  6. package/dist/api/controllers/datasource.js +2 -1
  7. package/dist/api/controllers/public/metrics.js +113 -0
  8. package/dist/api/controllers/row/external.js +16 -8
  9. package/dist/api/controllers/row/index.js +11 -1
  10. package/dist/api/controllers/row/internal.js +1 -10
  11. package/dist/api/controllers/row/utils.js +7 -7
  12. package/dist/api/controllers/static/index.js +84 -24
  13. package/dist/api/controllers/static/templates/BudibaseApp.svelte +33 -10
  14. package/dist/api/controllers/table/external.js +16 -12
  15. package/dist/api/controllers/table/utils.js +15 -1
  16. package/dist/api/routes/public/index.js +8 -0
  17. package/dist/api/routes/public/metrics.js +30 -0
  18. package/dist/app.js +1 -0
  19. package/dist/constants/index.js +2 -1
  20. package/dist/integrations/googlesheets.js +125 -59
  21. package/dist/integrations/redis.js +1 -1
  22. package/dist/integrations/utils.js +17 -2
  23. package/dist/package.json +13 -12
  24. package/dist/sdk/users/utils.js +2 -1
  25. package/dist/tsconfig.build.tsbuildinfo +1 -1
  26. package/dist/utilities/global.js +17 -7
  27. package/jest.config.ts +1 -0
  28. package/package.json +14 -13
  29. package/scripts/test.sh +3 -3
  30. package/specs/openapi.json +39 -0
  31. package/specs/openapi.yaml +169 -0
  32. package/specs/resources/application.ts +11 -0
  33. package/specs/resources/index.ts +2 -0
  34. package/specs/resources/metrics.ts +81 -0
  35. package/src/api/controllers/application.ts +20 -21
  36. package/src/api/controllers/datasource.ts +2 -1
  37. package/src/api/controllers/public/metrics.ts +251 -0
  38. package/src/api/controllers/row/external.ts +26 -16
  39. package/src/api/controllers/row/index.ts +12 -2
  40. package/src/api/controllers/row/internal.ts +0 -7
  41. package/src/api/controllers/row/utils.ts +7 -7
  42. package/src/api/controllers/static/index.ts +69 -26
  43. package/src/api/controllers/static/templates/BudibaseApp.svelte +33 -10
  44. package/src/api/controllers/table/external.ts +24 -17
  45. package/src/api/controllers/table/index.ts +9 -9
  46. package/src/api/controllers/table/utils.ts +18 -2
  47. package/src/api/controllers/view/tests/__snapshots__/viewBuilder.spec.js.snap +48 -48
  48. package/src/api/routes/public/index.ts +10 -1
  49. package/src/api/routes/public/metrics.ts +28 -0
  50. package/src/api/routes/public/tests/metrics.spec.js +34 -0
  51. package/src/api/routes/tests/__snapshots__/datasource.spec.ts.snap +22 -22
  52. package/src/api/routes/tests/__snapshots__/view.spec.js.snap +5 -5
  53. package/src/api/routes/tests/appSync.spec.ts +31 -0
  54. package/src/api/routes/tests/internalSearch.spec.js +8 -7
  55. package/src/app.ts +2 -1
  56. package/src/automations/automationUtils.ts +1 -1
  57. package/src/automations/tests/automation.spec.ts +99 -0
  58. package/src/constants/index.ts +1 -0
  59. package/src/definitions/openapi.ts +15 -0
  60. package/src/integration-test/postgres.spec.ts +46 -52
  61. package/src/integrations/googlesheets.ts +143 -71
  62. package/src/integrations/redis.ts +1 -1
  63. package/src/integrations/tests/googlesheets.spec.ts +13 -13
  64. package/src/integrations/tests/redis.spec.ts +9 -5
  65. package/src/integrations/utils.ts +16 -4
  66. package/src/middleware/currentapp.ts +2 -2
  67. package/src/sdk/users/utils.ts +4 -1
  68. package/src/tests/jestEnv.ts +1 -0
  69. package/src/tests/jestSetup.ts +5 -1
  70. package/src/tests/utilities/TestConfiguration.ts +13 -0
  71. package/src/tests/utilities/structures.ts +13 -1
  72. package/src/utilities/global.ts +21 -9
  73. package/builder/assets/favicon.e7fc7733.png +0 -0
  74. package/builder/assets/index.b0e3aca6.css +0 -6
  75. package/src/automations/tests/automation.spec.js +0 -84
@@ -0,0 +1,34 @@
1
+ const setup = require("../../tests/utilities")
2
+
3
+ jest.setTimeout(30000)
4
+
5
+ describe("/metrics", () => {
6
+ let request = setup.getRequest()
7
+ let config = setup.getConfig()
8
+
9
+ afterAll(setup.afterAll)
10
+
11
+ // For some reason this cannot be a beforeAll or the test "should be able to update the user" fail
12
+ beforeEach(async () => {
13
+ await config.init()
14
+ })
15
+
16
+ describe("get", () => {
17
+ it("returns a list of metrics", async () => {
18
+ const res = await request
19
+ .get(`/api/public/v1/metrics`)
20
+ .set(config.defaultHeaders())
21
+ .expect("Content-Type", /text\/plain/)
22
+ .expect(200)
23
+ expect(res.text).toContain("budibase_tenant_user_count")
24
+ })
25
+
26
+ it("endpoint should not be publicly exposed", async () => {
27
+ await request
28
+ .get(`/api/public/v1/metrics`)
29
+ .set(config.publicHeaders())
30
+ .expect(403)
31
+ })
32
+ })
33
+
34
+ })
@@ -1,21 +1,21 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`/datasources fetch returns all the datasources from the server 1`] = `
4
- Array [
5
- Object {
6
- "config": Object {},
7
- "entities": Array [
8
- Object {
4
+ [
5
+ {
6
+ "config": {},
7
+ "entities": [
8
+ {
9
9
  "_id": "ta_users",
10
10
  "_rev": "1-2375e1bc58aeec664dc1b1f04ad43e44",
11
11
  "createdAt": "2020-01-01T00:00:00.000Z",
12
12
  "name": "Users",
13
13
  "primaryDisplay": "email",
14
- "schema": Object {
15
- "email": Object {
16
- "constraints": Object {
14
+ "schema": {
15
+ "email": {
16
+ "constraints": {
17
17
  "email": true,
18
- "length": Object {
18
+ "length": {
19
19
  "maximum": "",
20
20
  },
21
21
  "presence": true,
@@ -25,8 +25,8 @@ Array [
25
25
  "name": "email",
26
26
  "type": "string",
27
27
  },
28
- "firstName": Object {
29
- "constraints": Object {
28
+ "firstName": {
29
+ "constraints": {
30
30
  "presence": false,
31
31
  "type": "string",
32
32
  },
@@ -34,8 +34,8 @@ Array [
34
34
  "name": "firstName",
35
35
  "type": "string",
36
36
  },
37
- "lastName": Object {
38
- "constraints": Object {
37
+ "lastName": {
38
+ "constraints": {
39
39
  "presence": false,
40
40
  "type": "string",
41
41
  },
@@ -43,9 +43,9 @@ Array [
43
43
  "name": "lastName",
44
44
  "type": "string",
45
45
  },
46
- "roleId": Object {
47
- "constraints": Object {
48
- "inclusion": Array [
46
+ "roleId": {
47
+ "constraints": {
48
+ "inclusion": [
49
49
  "ADMIN",
50
50
  "POWER",
51
51
  "BASIC",
@@ -58,9 +58,9 @@ Array [
58
58
  "name": "roleId",
59
59
  "type": "options",
60
60
  },
61
- "status": Object {
62
- "constraints": Object {
63
- "inclusion": Array [
61
+ "status": {
62
+ "constraints": {
63
+ "inclusion": [
64
64
  "active",
65
65
  "inactive",
66
66
  ],
@@ -74,15 +74,15 @@ Array [
74
74
  },
75
75
  "type": "table",
76
76
  "updatedAt": "2020-01-01T00:00:00.000Z",
77
- "views": Object {},
77
+ "views": {},
78
78
  },
79
79
  ],
80
80
  "name": "Budibase DB",
81
81
  "source": "BUDIBASE",
82
82
  "type": "budibase",
83
83
  },
84
- Object {
85
- "config": Object {},
84
+ {
85
+ "config": {},
86
86
  "createdAt": "2020-01-01T00:00:00.000Z",
87
87
  "name": "Test",
88
88
  "source": "POSTGRES",
@@ -1,8 +1,8 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`/views query returns data for the created view 1`] = `
4
- Array [
5
- Object {
4
+ [
5
+ {
6
6
  "avg": 2333.3333333333335,
7
7
  "count": 3,
8
8
  "group": null,
@@ -15,8 +15,8 @@ Array [
15
15
  `;
16
16
 
17
17
  exports[`/views query returns data for the created view using a group by 1`] = `
18
- Array [
19
- Object {
18
+ [
19
+ {
20
20
  "avg": 1500,
21
21
  "count": 2,
22
22
  "group": "One",
@@ -25,7 +25,7 @@ Array [
25
25
  "sum": 3000,
26
26
  "sumsqr": 5000000,
27
27
  },
28
- Object {
28
+ {
29
29
  "avg": 4000,
30
30
  "count": 1,
31
31
  "group": "Two",
@@ -0,0 +1,31 @@
1
+ import * as setup from "./utilities"
2
+ import { roles, db as dbCore } from "@budibase/backend-core"
3
+
4
+ describe("/api/applications/:appId/sync", () => {
5
+ let request = setup.getRequest()
6
+ let config = setup.getConfig()
7
+ let app
8
+
9
+ afterAll(setup.afterAll)
10
+
11
+ beforeAll(async () => {
12
+ app = await config.init()
13
+ // create some users which we will use throughout the tests
14
+ await config.createUser({
15
+ email: "sync1@test.com",
16
+ roles: {
17
+ [app._id!]: roles.BUILTIN_ROLE_IDS.BASIC,
18
+ },
19
+ })
20
+ })
21
+
22
+ async function getUserMetadata() {
23
+ const { rows } = await config.searchRows(dbCore.InternalTable.USER_METADATA)
24
+ return rows
25
+ }
26
+
27
+ it("make sure that user metadata is correctly sync'd", async () => {
28
+ const rows = await getUserMetadata()
29
+ expect(rows.length).toBe(1)
30
+ })
31
+ })
@@ -1,6 +1,7 @@
1
+ const fetch = require("node-fetch")
2
+ fetch.mockSearch()
1
3
  const search = require("../../controllers/row/internalSearch")
2
4
  // this will be mocked out for _search endpoint
3
- const fetch = require("node-fetch")
4
5
  const PARAMS = {
5
6
  tableId: "ta_12345679abcdef",
6
7
  version: "1",
@@ -20,7 +21,7 @@ function checkLucene(resp, expected, params = PARAMS) {
20
21
  expect(json.bookmark).toBe(PARAMS.bookmark)
21
22
  }
22
23
  expect(json.include_docs).toBe(true)
23
- expect(json.q).toBe(`(${expected}) AND tableId:"${params.tableId}"`)
24
+ expect(json.q).toBe(`${expected} AND tableId:"${params.tableId}"`)
24
25
  expect(json.limit).toBe(params.limit || 50)
25
26
  }
26
27
 
@@ -59,7 +60,7 @@ describe("internal search", () => {
59
60
  "column": "1",
60
61
  }
61
62
  }, PARAMS)
62
- checkLucene(response, `column:"2" OR !column:"1"`)
63
+ checkLucene(response, `(column:"2" OR !column:"1")`)
63
64
  })
64
65
 
65
66
  it("test AND query", async () => {
@@ -71,7 +72,7 @@ describe("internal search", () => {
71
72
  "column": "1",
72
73
  }
73
74
  }, PARAMS)
74
- checkLucene(response, `*:* AND column:"2" AND !column:"1"`)
75
+ checkLucene(response, `(*:* AND column:"2" AND !column:"1")`)
75
76
  })
76
77
 
77
78
  it("test pagination query", async () => {
@@ -132,7 +133,7 @@ describe("internal search", () => {
132
133
  "colArr": [1, 2, 3],
133
134
  },
134
135
  }, PARAMS)
135
- checkLucene(response, `*:* AND column:a AND colArr:(1 AND 2 AND 3)`, PARAMS)
136
+ checkLucene(response, `(*:* AND column:a AND colArr:(1 AND 2 AND 3))`, PARAMS)
136
137
  })
137
138
 
138
139
  it("test multiple of same column", async () => {
@@ -144,7 +145,7 @@ describe("internal search", () => {
144
145
  "3:column": "c",
145
146
  },
146
147
  }, PARAMS)
147
- checkLucene(response, `column:"a" OR column:"b" OR column:"c"`, PARAMS)
148
+ checkLucene(response, `(column:"a" OR column:"b" OR column:"c")`, PARAMS)
148
149
  })
149
150
 
150
151
  it("check a weird case for lucene building", async () => {
@@ -191,6 +192,6 @@ describe("internal search", () => {
191
192
  expect(json.bookmark).toBe(PARAMS.bookmark)
192
193
  }
193
194
  expect(json.include_docs).toBe(true)
194
- expect(json.q).toBe(`(*:* AND column:"1") AND tableId:${PARAMS.tableId}`)
195
+ expect(json.q).toBe(`*:* AND column:"1" AND tableId:${PARAMS.tableId}`)
195
196
  })
196
197
  })
package/src/app.ts CHANGED
@@ -27,7 +27,7 @@ import * as api from "./api"
27
27
  import * as automations from "./automations"
28
28
  import { Thread } from "./threads"
29
29
  import * as redis from "./utilities/redis"
30
- import { events, logging, middleware } from "@budibase/backend-core"
30
+ import { events, logging, middleware, timers } from "@budibase/backend-core"
31
31
  import { initialise as initialiseWebsockets } from "./websocket"
32
32
  import { startup } from "./startup"
33
33
  const Sentry = require("@sentry/node")
@@ -84,6 +84,7 @@ server.on("close", async () => {
84
84
  }
85
85
  shuttingDown = true
86
86
  console.log("Server Closed")
87
+ timers.cleanup()
87
88
  await automations.shutdown()
88
89
  await redis.shutdown()
89
90
  events.shutdown()
@@ -23,7 +23,7 @@ import { LoopStep, LoopStepType, LoopInput } from "../definitions/automations"
23
23
  * @returns {object} The inputs object which has had all the various types supported by this function converted to their
24
24
  * primitive types.
25
25
  */
26
- export function cleanInputValues(inputs: Record<string, any>, schema: any) {
26
+ export function cleanInputValues(inputs: Record<string, any>, schema?: any) {
27
27
  if (schema == null) {
28
28
  return inputs
29
29
  }
@@ -0,0 +1,99 @@
1
+ jest.mock("../../threads/automation")
2
+ jest.mock("../../utilities/redis", () => ({
3
+ init: jest.fn(),
4
+ checkTestFlag: () => {
5
+ return false
6
+ },
7
+ }))
8
+
9
+ jest.spyOn(global.console, "error")
10
+
11
+ import "../../environment"
12
+ import * as automation from "../index"
13
+ import * as thread from "../../threads/automation"
14
+ import * as triggers from "../triggers"
15
+ import { basicAutomation } from "../../tests/utilities/structures"
16
+ import { wait } from "../../utilities"
17
+ import { makePartial } from "../../tests/utilities"
18
+ import { cleanInputValues } from "../automationUtils"
19
+ import * as setup from "./utilities"
20
+ import { Automation } from "@budibase/types"
21
+
22
+ describe("Run through some parts of the automations system", () => {
23
+ let config = setup.getConfig()
24
+
25
+ beforeAll(async () => {
26
+ await automation.init()
27
+ await config.init()
28
+ })
29
+
30
+ afterAll(async () => {
31
+ await automation.shutdown()
32
+ setup.afterAll()
33
+ })
34
+
35
+ it("should be able to init in builder", async () => {
36
+ const automation: Automation = {
37
+ ...basicAutomation(),
38
+ appId: config.appId,
39
+ }
40
+ const fields: any = { a: 1, appId: config.appId }
41
+ await triggers.externalTrigger(automation, fields)
42
+ await wait(100)
43
+ expect(thread.execute).toHaveBeenCalled()
44
+ })
45
+
46
+ it("should check coercion", async () => {
47
+ const table = await config.createTable()
48
+ const automation: any = basicAutomation()
49
+ automation.definition.trigger.inputs.tableId = table._id
50
+ automation.definition.trigger.stepId = "APP"
51
+ automation.definition.trigger.inputs.fields = { a: "number" }
52
+ const fields: any = {
53
+ appId: config.getAppId(),
54
+ fields: {
55
+ a: "1",
56
+ },
57
+ }
58
+ await triggers.externalTrigger(automation, fields)
59
+ await wait(100)
60
+ expect(thread.execute).toHaveBeenCalledWith(
61
+ makePartial({
62
+ data: {
63
+ event: {
64
+ fields: {
65
+ a: 1,
66
+ },
67
+ },
68
+ },
69
+ }),
70
+ expect.any(Function)
71
+ )
72
+ })
73
+
74
+ it("should be able to clean inputs with the utilities", () => {
75
+ // can't clean without a schema
76
+ let output = cleanInputValues({ a: "1" })
77
+ expect(output.a).toBe("1")
78
+ output = cleanInputValues(
79
+ { a: "1", b: "true", c: "false", d: 1, e: "help" },
80
+ {
81
+ properties: {
82
+ a: {
83
+ type: "number",
84
+ },
85
+ b: {
86
+ type: "boolean",
87
+ },
88
+ c: {
89
+ type: "boolean",
90
+ },
91
+ },
92
+ }
93
+ )
94
+ expect(output.a).toBe(1)
95
+ expect(output.b).toBe(true)
96
+ expect(output.c).toBe(false)
97
+ expect(output.d).toBe(1)
98
+ })
99
+ })
@@ -180,3 +180,4 @@ export enum AutomationErrors {
180
180
  // pass through the list from the auth/core lib
181
181
  export const ObjectStoreBuckets = objectStore.ObjectStoreBuckets
182
182
  export const MAX_AUTOMATION_RECURRING_ERRORS = 5
183
+ export const GOOGLE_SHEETS_PRIMARY_KEY = "rowNumber"
@@ -22,6 +22,10 @@ export interface paths {
22
22
  /** Based on application properties (currently only name) search for applications. */
23
23
  post: operations["appSearch"];
24
24
  };
25
+ "/metrics": {
26
+ /** Output metrics in OpenMetrics format compatible with Prometheus */
27
+ get: operations["metricsGet"];
28
+ };
25
29
  "/queries/{queryId}": {
26
30
  /** Queries which have been created within a Budibase app can be executed using this, */
27
31
  post: operations["queryExecute"];
@@ -844,6 +848,17 @@ export interface operations {
844
848
  };
845
849
  };
846
850
  };
851
+ /** Output metrics in OpenMetrics format compatible with Prometheus */
852
+ metricsGet: {
853
+ responses: {
854
+ /** Returns tenant metrics. */
855
+ 200: {
856
+ content: {
857
+ "text/plain": string;
858
+ };
859
+ };
860
+ };
861
+ };
847
862
  /** Queries which have been created within a Budibase app can be executed using this, */
848
863
  queryExecute: {
849
864
  parameters: {
@@ -1,3 +1,6 @@
1
+ import fetch from "node-fetch"
2
+ // @ts-ignore
3
+ fetch.mockSearch()
1
4
  import {
2
5
  generateMakeRequest,
3
6
  MakeRequestResponse,
@@ -16,6 +19,7 @@ import _ from "lodash"
16
19
  import { generator } from "@budibase/backend-core/tests"
17
20
  import { utils } from "@budibase/backend-core"
18
21
  import { GenericContainer } from "testcontainers"
22
+ import { generateRowIdField } from "../integrations/utils"
19
23
 
20
24
  const config = setup.getConfig()!
21
25
 
@@ -80,16 +84,10 @@ describe("row api - postgres", () => {
80
84
  name: "id",
81
85
  type: FieldType.AUTO,
82
86
  autocolumn: true,
83
- constraints: {
84
- presence: true,
85
- },
86
87
  },
87
88
  title: {
88
89
  name: "title",
89
90
  type: FieldType.STRING,
90
- constraints: {
91
- presence: true,
92
- },
93
91
  },
94
92
  },
95
93
  sourceId: postgresDatasource._id,
@@ -121,16 +119,10 @@ describe("row api - postgres", () => {
121
119
  name: "id",
122
120
  type: FieldType.AUTO,
123
121
  autocolumn: true,
124
- constraints: {
125
- presence: true,
126
- },
127
122
  },
128
123
  name: {
129
124
  name: "name",
130
125
  type: FieldType.STRING,
131
- constraints: {
132
- presence: true,
133
- },
134
126
  },
135
127
  description: {
136
128
  name: "description",
@@ -144,7 +136,6 @@ describe("row api - postgres", () => {
144
136
  type: FieldType.LINK,
145
137
  constraints: {
146
138
  type: "array",
147
- presence: false,
148
139
  },
149
140
  fieldName: oneToManyRelationshipInfo.fieldName,
150
141
  name: "oneToManyRelation",
@@ -156,7 +147,6 @@ describe("row api - postgres", () => {
156
147
  type: FieldType.LINK,
157
148
  constraints: {
158
149
  type: "array",
159
- presence: false,
160
150
  },
161
151
  fieldName: manyToOneRelationshipInfo.fieldName,
162
152
  name: "manyToOneRelation",
@@ -168,7 +158,6 @@ describe("row api - postgres", () => {
168
158
  type: FieldType.LINK,
169
159
  constraints: {
170
160
  type: "array",
171
- presence: false,
172
161
  },
173
162
  fieldName: manyToManyRelationshipInfo.fieldName,
174
163
  name: "manyToManyRelation",
@@ -309,9 +298,6 @@ describe("row api - postgres", () => {
309
298
  id: {
310
299
  name: "id",
311
300
  type: FieldType.AUTO,
312
- constraints: {
313
- presence: true,
314
- },
315
301
  },
316
302
  },
317
303
  sourceId: postgresDatasource._id,
@@ -921,47 +907,55 @@ describe("row api - postgres", () => {
921
907
  foreignRows,
922
908
  x => x.relationshipType
923
909
  )
924
- expect(res.body).toEqual({
925
- ...rowData,
926
- [`fk_${oneToManyRelationshipInfo.table.name}_${oneToManyRelationshipInfo.fieldName}`]:
927
- foreignRowsByType[RelationshipTypes.ONE_TO_MANY][0].row.id,
928
- [oneToManyRelationshipInfo.fieldName]: [
929
- {
930
- ...foreignRowsByType[RelationshipTypes.ONE_TO_MANY][0].row,
931
- _id: expect.any(String),
932
- _rev: expect.any(String),
933
- },
934
- ],
935
- [manyToOneRelationshipInfo.fieldName]: [
936
- {
937
- ...foreignRowsByType[RelationshipTypes.MANY_TO_ONE][0].row,
938
- [`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
939
- row.id,
940
- },
941
- {
942
- ...foreignRowsByType[RelationshipTypes.MANY_TO_ONE][1].row,
943
- [`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
944
- row.id,
945
- },
910
+ const m2mFieldName = manyToManyRelationshipInfo.fieldName,
911
+ o2mFieldName = oneToManyRelationshipInfo.fieldName,
912
+ m2oFieldName = manyToOneRelationshipInfo.fieldName
913
+ const m2mRow1 = res.body[m2mFieldName].find(
914
+ (row: Row) => row.id === 1
915
+ )
916
+ const m2mRow2 = res.body[m2mFieldName].find(
917
+ (row: Row) => row.id === 2
918
+ )
919
+ expect(m2mRow1).toEqual({
920
+ ...foreignRowsByType[RelationshipTypes.MANY_TO_MANY][0].row,
921
+ [m2mFieldName]: [
946
922
  {
947
- ...foreignRowsByType[RelationshipTypes.MANY_TO_ONE][2].row,
948
- [`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
949
- row.id,
923
+ _id: row._id,
950
924
  },
951
925
  ],
952
- [manyToManyRelationshipInfo.fieldName]: [
953
- {
954
- ...foreignRowsByType[RelationshipTypes.MANY_TO_MANY][0].row,
955
- },
926
+ })
927
+ expect(m2mRow2).toEqual({
928
+ ...foreignRowsByType[RelationshipTypes.MANY_TO_MANY][1].row,
929
+ [m2mFieldName]: [
956
930
  {
957
- ...foreignRowsByType[RelationshipTypes.MANY_TO_MANY][1].row,
931
+ _id: row._id,
958
932
  },
959
933
  ],
960
- id: row.id,
961
- tableId: row.tableId,
962
- _id: expect.any(String),
963
- _rev: expect.any(String),
964
934
  })
935
+ expect(res.body[m2oFieldName]).toEqual([
936
+ {
937
+ ...foreignRowsByType[RelationshipTypes.MANY_TO_ONE][0].row,
938
+ [`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
939
+ row.id,
940
+ },
941
+ {
942
+ ...foreignRowsByType[RelationshipTypes.MANY_TO_ONE][1].row,
943
+ [`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
944
+ row.id,
945
+ },
946
+ {
947
+ ...foreignRowsByType[RelationshipTypes.MANY_TO_ONE][2].row,
948
+ [`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
949
+ row.id,
950
+ },
951
+ ])
952
+ expect(res.body[o2mFieldName]).toEqual([
953
+ {
954
+ ...foreignRowsByType[RelationshipTypes.ONE_TO_MANY][0].row,
955
+ _id: expect.any(String),
956
+ _rev: expect.any(String),
957
+ },
958
+ ])
965
959
  })
966
960
  })
967
961
  })