directus 9.20.3 → 9.21.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 (137) hide show
  1. package/dist/cli/utils/create-db-connection.d.ts +1 -1
  2. package/dist/controllers/extensions.js +4 -13
  3. package/dist/database/helpers/date/dialects/sqlite.d.ts +1 -1
  4. package/dist/database/helpers/date/dialects/sqlite.js +4 -0
  5. package/dist/database/helpers/date/types.d.ts +1 -1
  6. package/dist/database/helpers/date/types.js +4 -0
  7. package/dist/database/helpers/fn/dialects/mssql.d.ts +8 -8
  8. package/dist/database/helpers/fn/dialects/mssql.js +22 -16
  9. package/dist/database/helpers/fn/dialects/mysql.d.ts +8 -8
  10. package/dist/database/helpers/fn/dialects/mysql.js +22 -16
  11. package/dist/database/helpers/fn/dialects/postgres.d.ts +8 -8
  12. package/dist/database/helpers/fn/dialects/postgres.js +22 -16
  13. package/dist/database/helpers/fn/types.d.ts +1 -1
  14. package/dist/database/helpers/index.d.ts +1 -1
  15. package/dist/database/helpers/schema/dialects/cockroachdb.d.ts +1 -0
  16. package/dist/database/helpers/schema/dialects/cockroachdb.js +11 -0
  17. package/dist/database/helpers/schema/types.d.ts +3 -2
  18. package/dist/database/helpers/schema/types.js +5 -0
  19. package/dist/database/migrations/run.js +29 -3
  20. package/dist/database/run-ast.d.ts +1 -1
  21. package/dist/database/run-ast.js +1 -1
  22. package/dist/env.d.ts +4 -0
  23. package/dist/env.js +9 -4
  24. package/dist/env.test.d.ts +1 -8
  25. package/dist/exceptions/database/contains-null-values.d.ts +1 -1
  26. package/dist/exceptions/database/dialects/types.d.ts +6 -6
  27. package/dist/exceptions/database/invalid-foreign-key.d.ts +1 -1
  28. package/dist/exceptions/database/not-null-violation.d.ts +1 -1
  29. package/dist/exceptions/database/record-not-unique.d.ts +1 -1
  30. package/dist/exceptions/database/value-out-of-range.d.ts +1 -1
  31. package/dist/exceptions/database/value-too-long.d.ts +1 -1
  32. package/dist/exceptions/hit-rate-limit.d.ts +1 -1
  33. package/dist/exceptions/method-not-allowed.d.ts +1 -1
  34. package/dist/exceptions/service-unavailable.d.ts +1 -1
  35. package/dist/extensions.d.ts +7 -7
  36. package/dist/extensions.js +92 -89
  37. package/dist/logger.d.ts +1 -0
  38. package/dist/messenger.d.ts +1 -1
  39. package/dist/middleware/authenticate.d.ts +1 -0
  40. package/dist/middleware/validate-batch.d.ts +2 -0
  41. package/dist/operations/condition/index.d.ts +1 -1
  42. package/dist/operations/condition/index.js +1 -1
  43. package/dist/operations/condition/index.test.d.ts +1 -0
  44. package/dist/operations/exec/index.d.ts +1 -1
  45. package/dist/operations/item-create/index.d.ts +1 -1
  46. package/dist/operations/item-delete/index.d.ts +1 -1
  47. package/dist/operations/item-read/index.d.ts +1 -1
  48. package/dist/operations/item-update/index.d.ts +1 -1
  49. package/dist/operations/log/index.d.ts +1 -1
  50. package/dist/operations/mail/index.d.ts +1 -1
  51. package/dist/operations/notification/index.d.ts +1 -1
  52. package/dist/operations/request/index.d.ts +1 -1
  53. package/dist/operations/sleep/index.d.ts +1 -1
  54. package/dist/operations/transform/index.d.ts +1 -1
  55. package/dist/operations/trigger/index.d.ts +1 -1
  56. package/dist/operations/trigger/index.js +5 -2
  57. package/dist/rate-limiter.d.ts +1 -1
  58. package/dist/services/authorization.js +7 -3
  59. package/dist/services/collections.d.ts +1 -1
  60. package/dist/services/collections.js +112 -13
  61. package/dist/services/fields.d.ts +2 -2
  62. package/dist/services/fields.js +89 -41
  63. package/dist/services/fields.test.d.ts +1 -0
  64. package/dist/services/graphql/index.js +4 -1
  65. package/dist/services/graphql/types/bigint.d.ts +1 -1
  66. package/dist/services/graphql/types/bigint.js +4 -0
  67. package/dist/services/graphql/utils/process-error.d.ts +4 -0
  68. package/dist/services/graphql/utils/process-error.js +26 -0
  69. package/dist/services/graphql/utils/process-error.test.d.ts +1 -0
  70. package/dist/services/items.d.ts +1 -1
  71. package/dist/services/items.js +39 -13
  72. package/dist/services/mail/index.d.ts +2 -2
  73. package/dist/services/mail/index.js +2 -1
  74. package/dist/services/mail/templates/base.liquid +4 -4
  75. package/dist/services/notifications.js +9 -4
  76. package/dist/services/notifications.test.d.ts +1 -0
  77. package/dist/services/payload.d.ts +2 -2
  78. package/dist/services/payload.js +14 -12
  79. package/dist/services/relations.d.ts +2 -2
  80. package/dist/services/relations.js +54 -4
  81. package/dist/services/users.js +2 -2
  82. package/dist/services/users.test.d.ts +1 -0
  83. package/dist/types/assets.d.ts +7 -7
  84. package/dist/types/ast.d.ts +7 -7
  85. package/dist/types/auth.d.ts +4 -4
  86. package/dist/types/collection.d.ts +2 -2
  87. package/dist/types/events.d.ts +1 -1
  88. package/dist/types/files.d.ts +2 -2
  89. package/dist/types/items.d.ts +5 -5
  90. package/dist/types/migration.d.ts +1 -1
  91. package/dist/types/revision.d.ts +1 -1
  92. package/dist/types/services.d.ts +1 -1
  93. package/dist/types/snapshot.d.ts +4 -4
  94. package/dist/types/webhooks.d.ts +2 -2
  95. package/dist/utils/get-ast-from-query.d.ts +1 -1
  96. package/dist/utils/get-column-path.d.ts +2 -2
  97. package/dist/utils/get-module-default.d.ts +1 -1
  98. package/dist/utils/get-relation-info.d.ts +1 -1
  99. package/dist/utils/job-queue.d.ts +1 -1
  100. package/dist/utils/merge-permissions.d.ts +1 -0
  101. package/dist/utils/reduce-schema.js +3 -1
  102. package/package.json +70 -71
  103. package/dist/__mocks__/cache.d.ts +0 -5
  104. package/dist/__mocks__/cache.js +0 -7
  105. package/dist/__utils__/items-utils.d.ts +0 -2
  106. package/dist/__utils__/items-utils.js +0 -36
  107. package/dist/__utils__/schemas.d.ts +0 -13
  108. package/dist/__utils__/schemas.js +0 -304
  109. package/dist/__utils__/snapshots.d.ts +0 -5
  110. package/dist/__utils__/snapshots.js +0 -897
  111. package/dist/cli/index.test.js +0 -63
  112. package/dist/controllers/files.test.js +0 -49
  113. package/dist/database/migrations/run.test.js +0 -92
  114. package/dist/env.test.js +0 -40
  115. package/dist/middleware/authenticate.test.js +0 -214
  116. package/dist/middleware/extract-token.test.js +0 -60
  117. package/dist/middleware/validate-batch.test.js +0 -82
  118. package/dist/operations/exec/index.test.js +0 -95
  119. package/dist/services/files.test.js +0 -89
  120. package/dist/services/items.test.js +0 -765
  121. package/dist/services/payload.test.js +0 -196
  122. package/dist/services/specifications.test.js +0 -96
  123. package/dist/utils/apply-snapshot.test.js +0 -305
  124. package/dist/utils/async-handler.test.js +0 -18
  125. package/dist/utils/calculate-field-depth.test.js +0 -76
  126. package/dist/utils/filter-items.test.js +0 -60
  127. package/dist/utils/get-auth-providers.test.js +0 -72
  128. package/dist/utils/get-cache-key.test.js +0 -74
  129. package/dist/utils/get-column-path.test.js +0 -136
  130. package/dist/utils/get-config-from-env.test.js +0 -19
  131. package/dist/utils/get-relation-info.test.js +0 -88
  132. package/dist/utils/get-relation-type.test.js +0 -69
  133. package/dist/utils/get-string-byte-size.test.js +0 -8
  134. package/dist/utils/is-directus-jwt.test.js +0 -26
  135. package/dist/utils/jwt.test.js +0 -36
  136. package/dist/utils/merge-permissions.test.js +0 -80
  137. package/dist/utils/validate-keys.test.js +0 -97
@@ -1,196 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const knex_1 = __importDefault(require("knex"));
7
- const knex_mock_client_1 = require("knex-mock-client");
8
- const services_1 = require("../../src/services");
9
- const helpers_1 = require("../../src/database/helpers");
10
- jest.mock('../../src/database/index', () => {
11
- return { getDatabaseClient: jest.fn().mockReturnValue('postgres') };
12
- });
13
- jest.requireMock('../../src/database/index');
14
- describe('Integration Tests', () => {
15
- let db;
16
- let tracker;
17
- beforeAll(async () => {
18
- db = (0, knex_1.default)({ client: knex_mock_client_1.MockClient });
19
- tracker = (0, knex_mock_client_1.getTracker)();
20
- });
21
- afterEach(() => {
22
- tracker.reset();
23
- });
24
- describe('Services / PayloadService', () => {
25
- describe('transformers', () => {
26
- let service;
27
- let helpers;
28
- beforeEach(() => {
29
- service = new services_1.PayloadService('test', {
30
- knex: db,
31
- schema: { collections: {}, relations: [] },
32
- });
33
- helpers = (0, helpers_1.getHelpers)(db);
34
- });
35
- describe('csv', () => {
36
- it('Returns undefined for illegal values', async () => {
37
- const result = await service.transformers['cast-csv']({
38
- value: 123,
39
- action: 'read',
40
- payload: {},
41
- accountability: { role: null },
42
- specials: [],
43
- helpers,
44
- });
45
- expect(result).toBe(undefined);
46
- });
47
- it('Returns [] for empty strings', async () => {
48
- const result = await service.transformers['cast-csv']({
49
- value: '',
50
- action: 'read',
51
- payload: {},
52
- accountability: { role: null },
53
- specials: [],
54
- helpers,
55
- });
56
- expect(result).toMatchObject([]);
57
- });
58
- it('Splits the CSV string', async () => {
59
- const result = await service.transformers['cast-csv']({
60
- value: 'test,directus',
61
- action: 'read',
62
- payload: {},
63
- accountability: { role: null },
64
- specials: [],
65
- helpers,
66
- });
67
- expect(result).toMatchObject(['test', 'directus']);
68
- });
69
- it('Saves array values as joined string', async () => {
70
- const result = await service.transformers['cast-csv']({
71
- value: ['test', 'directus'],
72
- action: 'create',
73
- payload: {},
74
- accountability: { role: null },
75
- specials: [],
76
- helpers,
77
- });
78
- expect(result).toBe('test,directus');
79
- });
80
- it('Saves string values as is', async () => {
81
- const result = await service.transformers['cast-csv']({
82
- value: 'test,directus',
83
- action: 'create',
84
- payload: {},
85
- accountability: { role: null },
86
- specials: [],
87
- helpers,
88
- });
89
- expect(result).toBe('test,directus');
90
- });
91
- });
92
- });
93
- describe('processDates', () => {
94
- let service;
95
- const dateFieldId = 'date_field';
96
- const dateTimeFieldId = 'datetime_field';
97
- const timestampFieldId = 'timestamp_field';
98
- beforeEach(() => {
99
- service = new services_1.PayloadService('test', {
100
- knex: db,
101
- schema: {
102
- collections: {
103
- test: {
104
- collection: 'test',
105
- primary: 'id',
106
- singleton: false,
107
- sortField: null,
108
- note: null,
109
- accountability: null,
110
- fields: {
111
- [dateFieldId]: {
112
- field: dateFieldId,
113
- defaultValue: null,
114
- nullable: true,
115
- generated: false,
116
- type: 'date',
117
- dbType: 'date',
118
- precision: null,
119
- scale: null,
120
- special: [],
121
- note: null,
122
- validation: null,
123
- alias: false,
124
- },
125
- [dateTimeFieldId]: {
126
- field: dateTimeFieldId,
127
- defaultValue: null,
128
- nullable: true,
129
- generated: false,
130
- type: 'dateTime',
131
- dbType: 'datetime',
132
- precision: null,
133
- scale: null,
134
- special: [],
135
- note: null,
136
- validation: null,
137
- alias: false,
138
- },
139
- [timestampFieldId]: {
140
- field: timestampFieldId,
141
- defaultValue: null,
142
- nullable: true,
143
- generated: false,
144
- type: 'timestamp',
145
- dbType: 'timestamp',
146
- precision: null,
147
- scale: null,
148
- special: [],
149
- note: null,
150
- validation: null,
151
- alias: false,
152
- },
153
- },
154
- },
155
- },
156
- relations: [],
157
- },
158
- });
159
- });
160
- describe('processes dates', () => {
161
- it('with zero values', async () => {
162
- const result = await service.processDates([
163
- {
164
- [dateFieldId]: '0000-00-00',
165
- [dateTimeFieldId]: '0000-00-00 00:00:00',
166
- [timestampFieldId]: '0000-00-00 00:00:00.000',
167
- },
168
- ], 'read');
169
- expect(result).toMatchObject([
170
- {
171
- [dateFieldId]: null,
172
- [dateTimeFieldId]: null,
173
- [timestampFieldId]: null,
174
- },
175
- ]);
176
- });
177
- it('with typical values', async () => {
178
- const result = await service.processDates([
179
- {
180
- [dateFieldId]: '2022-01-10',
181
- [dateTimeFieldId]: '2021-09-31 12:34:56',
182
- [timestampFieldId]: '1980-12-08 00:11:22.333',
183
- },
184
- ], 'read');
185
- expect(result).toMatchObject([
186
- {
187
- [dateFieldId]: '2022-01-10',
188
- [dateTimeFieldId]: '2021-10-01T12:34:56',
189
- [timestampFieldId]: new Date('1980-12-08 00:11:22.333').toISOString(),
190
- },
191
- ]);
192
- });
193
- });
194
- });
195
- });
196
- });
@@ -1,96 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const knex_1 = __importDefault(require("knex"));
7
- const knex_mock_client_1 = require("knex-mock-client");
8
- const services_1 = require("../../src/services");
9
- jest.mock('../../src/database/index', () => {
10
- return { getDatabaseClient: jest.fn().mockReturnValue('postgres') };
11
- });
12
- jest.requireMock('../../src/database/index');
13
- class Client_PG extends knex_mock_client_1.MockClient {
14
- }
15
- describe('Integration Tests', () => {
16
- let db;
17
- let tracker;
18
- beforeAll(async () => {
19
- db = (0, knex_1.default)({ client: Client_PG });
20
- tracker = (0, knex_mock_client_1.getTracker)();
21
- });
22
- afterEach(() => {
23
- tracker.reset();
24
- jest.clearAllMocks();
25
- });
26
- describe('Services / Specifications', () => {
27
- describe('oas', () => {
28
- describe('generate', () => {
29
- let service;
30
- beforeEach(() => {
31
- service = new services_1.SpecificationService({
32
- knex: db,
33
- schema: { collections: {}, relations: [] },
34
- });
35
- });
36
- it('returns untyped schema for json fields', async () => {
37
- var _a;
38
- jest.spyOn(services_1.CollectionsService.prototype, 'readByQuery').mockImplementation(jest.fn().mockReturnValue([
39
- {
40
- collection: 'test_table',
41
- meta: {
42
- accountability: 'all',
43
- collection: 'test_table',
44
- group: null,
45
- hidden: false,
46
- icon: null,
47
- item_duplication_fields: null,
48
- note: null,
49
- singleton: false,
50
- translations: null,
51
- },
52
- schema: {
53
- name: 'test_table',
54
- },
55
- },
56
- ]));
57
- jest.spyOn(services_1.FieldsService.prototype, 'readAll').mockImplementation(jest.fn().mockReturnValue([
58
- {
59
- collection: 'test_table',
60
- field: 'id',
61
- type: 'integer',
62
- schema: {
63
- is_nullable: false,
64
- },
65
- },
66
- {
67
- collection: 'test_table',
68
- field: 'blob',
69
- type: 'json',
70
- schema: {
71
- is_nullable: true,
72
- },
73
- },
74
- ]));
75
- jest.spyOn(services_1.RelationsService.prototype, 'readAll').mockImplementation(jest.fn().mockReturnValue([]));
76
- const spec = await service.oas.generate();
77
- expect((_a = spec.components) === null || _a === void 0 ? void 0 : _a.schemas).toEqual({
78
- ItemsTestTable: {
79
- type: 'object',
80
- properties: {
81
- id: {
82
- nullable: false,
83
- type: 'integer',
84
- },
85
- blob: {
86
- nullable: true,
87
- },
88
- },
89
- 'x-collection': 'test_table',
90
- },
91
- });
92
- });
93
- });
94
- });
95
- });
96
- });
@@ -1,305 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const knex_1 = __importDefault(require("knex"));
30
- const knex_mock_client_1 = require("knex-mock-client");
31
- const schemas_1 = require("../__utils__/schemas");
32
- const services_1 = require("../services");
33
- const apply_snapshot_1 = require("./apply-snapshot");
34
- const getSchema = __importStar(require("./get-schema"));
35
- const snapshots_1 = require("../__utils__/snapshots");
36
- jest.mock('../../src/database/index', () => {
37
- return {
38
- getDatabaseClient: jest.fn().mockReturnValue('postgres'),
39
- };
40
- });
41
- jest.requireMock('../../src/database/index');
42
- class Client_PG extends knex_mock_client_1.MockClient {
43
- }
44
- describe('applySnapshot', () => {
45
- let db;
46
- let tracker;
47
- beforeEach(() => {
48
- db = (0, knex_1.default)({ client: Client_PG });
49
- tracker = (0, knex_mock_client_1.getTracker)();
50
- });
51
- afterEach(() => {
52
- tracker.reset();
53
- jest.clearAllMocks();
54
- });
55
- describe('Creating new collection(s)', () => {
56
- it('Creates new top-level collection(s)', async () => {
57
- const expected = {
58
- collection: 'test_table_2',
59
- meta: {
60
- accountability: 'all',
61
- collection: 'test_table_2',
62
- group: null,
63
- hidden: true,
64
- icon: 'import_export',
65
- item_duplication_fields: null,
66
- note: null,
67
- singleton: false,
68
- translations: {},
69
- },
70
- schema: { comment: null, name: 'test_table_2', schema: 'public' },
71
- fields: [
72
- {
73
- collection: 'test_table_2',
74
- field: 'id',
75
- meta: {
76
- collection: 'test_table_2',
77
- conditions: null,
78
- display: null,
79
- display_options: null,
80
- field: 'id',
81
- group: null,
82
- hidden: true,
83
- interface: null,
84
- note: null,
85
- options: null,
86
- readonly: false,
87
- required: false,
88
- sort: null,
89
- special: null,
90
- translations: {},
91
- validation: null,
92
- validation_message: null,
93
- width: 'full',
94
- },
95
- schema: {
96
- comment: null,
97
- data_type: 'uuid',
98
- default_value: null,
99
- foreign_key_column: null,
100
- foreign_key_schema: null,
101
- foreign_key_table: null,
102
- generation_expression: null,
103
- has_auto_increment: false,
104
- is_generated: false,
105
- is_nullable: false,
106
- is_primary_key: true,
107
- is_unique: true,
108
- max_length: null,
109
- name: 'id',
110
- numeric_precision: null,
111
- numeric_scale: null,
112
- schema: 'public',
113
- table: 'test_table_2',
114
- },
115
- type: 'uuid',
116
- },
117
- ],
118
- };
119
- // Stop call to db later on in apply-snapshot
120
- jest.spyOn(getSchema, 'getSchema').mockReturnValue(Promise.resolve(schemas_1.snapshotApplyTestSchema));
121
- // We are not actually testing that createOne works, just that is is called correctly
122
- const createOneCollectionSpy = jest
123
- .spyOn(services_1.CollectionsService.prototype, 'createOne')
124
- .mockImplementation(jest.fn());
125
- const createFieldSpy = jest.spyOn(services_1.FieldsService.prototype, 'createField').mockImplementation(jest.fn());
126
- await (0, apply_snapshot_1.applySnapshot)(snapshots_1.snapshotCreateCollectionNotNested, {
127
- database: db,
128
- current: snapshots_1.snapshotBeforeCreateCollection,
129
- schema: schemas_1.snapshotApplyTestSchema,
130
- });
131
- expect(createOneCollectionSpy).toHaveBeenCalledTimes(1);
132
- expect(createOneCollectionSpy).toHaveBeenCalledWith(expected);
133
- // There should be no fields left to create
134
- // they will get filtered in createCollections
135
- expect(createFieldSpy).toHaveBeenCalledTimes(0);
136
- });
137
- it('Creates the highest-level nested collection(s) with existing parents and any children', async () => {
138
- const expected = {
139
- collection: 'test_table_2',
140
- meta: {
141
- accountability: 'all',
142
- collection: 'test_table_2',
143
- group: 'test_table',
144
- hidden: true,
145
- icon: 'import_export',
146
- item_duplication_fields: null,
147
- note: null,
148
- singleton: false,
149
- translations: {},
150
- },
151
- schema: { comment: null, name: 'test_table_2', schema: 'public' },
152
- fields: [
153
- {
154
- collection: 'test_table_2',
155
- field: 'id',
156
- meta: {
157
- collection: 'test_table_2',
158
- conditions: null,
159
- display: null,
160
- display_options: null,
161
- field: 'id',
162
- group: null,
163
- hidden: true,
164
- interface: null,
165
- note: null,
166
- options: null,
167
- readonly: false,
168
- required: false,
169
- sort: null,
170
- special: null,
171
- translations: {},
172
- validation: null,
173
- validation_message: null,
174
- width: 'full',
175
- },
176
- schema: {
177
- comment: null,
178
- data_type: 'uuid',
179
- default_value: null,
180
- foreign_key_column: null,
181
- foreign_key_schema: null,
182
- foreign_key_table: null,
183
- generation_expression: null,
184
- has_auto_increment: false,
185
- is_generated: false,
186
- is_nullable: false,
187
- is_primary_key: true,
188
- is_unique: true,
189
- max_length: null,
190
- name: 'id',
191
- numeric_precision: null,
192
- numeric_scale: null,
193
- schema: 'public',
194
- table: 'test_table_2',
195
- },
196
- type: 'uuid',
197
- },
198
- ],
199
- };
200
- const expected2 = {
201
- collection: 'test_table_3',
202
- fields: [
203
- {
204
- collection: 'test_table_3',
205
- field: 'id',
206
- meta: {
207
- collection: 'test_table_3',
208
- conditions: null,
209
- display: null,
210
- display_options: null,
211
- field: 'id',
212
- group: null,
213
- hidden: true,
214
- interface: null,
215
- note: null,
216
- options: null,
217
- readonly: false,
218
- required: false,
219
- sort: null,
220
- special: null,
221
- translations: {},
222
- validation: null,
223
- validation_message: null,
224
- width: 'full',
225
- },
226
- schema: {
227
- comment: null,
228
- data_type: 'uuid',
229
- default_value: null,
230
- foreign_key_column: null,
231
- foreign_key_schema: null,
232
- foreign_key_table: null,
233
- generation_expression: null,
234
- has_auto_increment: false,
235
- is_generated: false,
236
- is_nullable: false,
237
- is_primary_key: true,
238
- is_unique: true,
239
- max_length: null,
240
- name: 'id',
241
- numeric_precision: null,
242
- numeric_scale: null,
243
- schema: 'public',
244
- table: 'test_table_3',
245
- },
246
- type: 'uuid',
247
- },
248
- ],
249
- meta: {
250
- accountability: 'all',
251
- collection: 'test_table_3',
252
- group: 'test_table_2',
253
- hidden: true,
254
- icon: 'import_export',
255
- item_duplication_fields: null,
256
- note: null,
257
- singleton: false,
258
- translations: {},
259
- },
260
- schema: { comment: null, name: 'test_table_3', schema: 'public' },
261
- };
262
- // Stop call to db later on in apply-snapshot
263
- jest.spyOn(getSchema, 'getSchema').mockReturnValue(Promise.resolve(schemas_1.snapshotApplyTestSchema));
264
- // We are not actually testing that createOne works, just that is is called correctly
265
- const createOneCollectionSpy = jest
266
- .spyOn(services_1.CollectionsService.prototype, 'createOne')
267
- .mockImplementation(jest.fn());
268
- const createFieldSpy = jest.spyOn(services_1.FieldsService.prototype, 'createField').mockImplementation(jest.fn());
269
- await (0, apply_snapshot_1.applySnapshot)(snapshots_1.snapshotCreateCollection, {
270
- database: db,
271
- current: snapshots_1.snapshotBeforeCreateCollection,
272
- schema: schemas_1.snapshotApplyTestSchema,
273
- });
274
- expect(createOneCollectionSpy).toHaveBeenCalledTimes(2);
275
- expect(createOneCollectionSpy).toHaveBeenCalledWith(expected);
276
- expect(createOneCollectionSpy).toHaveBeenCalledWith(expected2);
277
- // There should be no fields left to create
278
- // they will get filtered in createCollections
279
- expect(createFieldSpy).toHaveBeenCalledTimes(0);
280
- });
281
- });
282
- describe('Delete collections', () => {
283
- it('Deletes interrelated collections', async () => {
284
- const snapshotToApply = {
285
- version: 1,
286
- directus: '0.0.0',
287
- collections: [],
288
- fields: [],
289
- relations: [],
290
- };
291
- // Stop call to db later on in apply-snapshot
292
- jest.spyOn(getSchema, 'getSchema').mockReturnValue(Promise.resolve(schemas_1.snapshotApplyTestSchema));
293
- // We are not actually testing that deleteOne works, just that is is called correctly
294
- const deleteOneCollectionSpy = jest
295
- .spyOn(services_1.CollectionsService.prototype, 'deleteOne')
296
- .mockImplementation(jest.fn());
297
- await (0, apply_snapshot_1.applySnapshot)(snapshotToApply, {
298
- database: db,
299
- current: snapshots_1.snapshotBeforeDeleteCollection,
300
- schema: schemas_1.snapshotApplyTestSchema,
301
- });
302
- expect(deleteOneCollectionSpy).toHaveBeenCalledTimes(3);
303
- });
304
- });
305
- });
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- require("../../src/types/express.d.ts");
7
- const async_handler_1 = __importDefault(require("./async-handler"));
8
- let mockRequest;
9
- let mockResponse;
10
- const nextFunction = jest.fn();
11
- test('Wraps async middleware in Promise resolve that will catch rejects and pass them to the nextFn', async () => {
12
- const err = new Error('testing');
13
- const middleware = async (_req, _res, _next) => {
14
- throw err;
15
- };
16
- await (0, async_handler_1.default)(middleware)(mockRequest, mockResponse, nextFunction);
17
- expect(nextFunction).toHaveBeenCalledWith(err);
18
- });