@terreno/api 0.10.0 → 0.11.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.
package/dist/plugins.js CHANGED
@@ -95,23 +95,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
95
95
  }
96
96
  };
97
97
  Object.defineProperty(exports, "__esModule", { value: true });
98
- exports.DateOnly = void 0;
99
- exports.baseUserPlugin = baseUserPlugin;
100
- exports.isDeletedPlugin = isDeletedPlugin;
101
- exports.isDisabledPlugin = isDisabledPlugin;
102
- exports.createdUpdatedPlugin = createdUpdatedPlugin;
103
- exports.firebaseJWTPlugin = firebaseJWTPlugin;
104
- exports.findOneOrNone = findOneOrNone;
105
- exports.findExactlyOne = findExactlyOne;
106
- exports.upsertPlugin = upsertPlugin;
98
+ exports.DateOnly = exports.upsertPlugin = exports.findExactlyOne = exports.findOneOrNone = exports.firebaseJWTPlugin = exports.createdUpdatedPlugin = exports.isDisabledPlugin = exports.isDeletedPlugin = exports.baseUserPlugin = void 0;
107
99
  var luxon_1 = require("luxon");
108
100
  var mongoose_1 = __importStar(require("mongoose"));
109
101
  var errors_1 = require("./errors");
110
- function baseUserPlugin(schema) {
111
- schema.add({ admin: { default: false, type: Boolean } });
112
- schema.add({ email: { index: true, type: String } });
113
- }
114
- function isDeletedPlugin(schema, defaultValue) {
102
+ var baseUserPlugin = function (schema) {
103
+ schema.add({
104
+ admin: { default: false, description: "Whether the user has admin privileges", type: Boolean },
105
+ });
106
+ schema.add({ email: { description: "The user's email address", index: true, type: String } });
107
+ };
108
+ exports.baseUserPlugin = baseUserPlugin;
109
+ var isDeletedPlugin = function (schema, defaultValue) {
115
110
  if (defaultValue === void 0) { defaultValue = false; }
116
111
  schema.add({
117
112
  deleted: {
@@ -122,20 +117,21 @@ function isDeletedPlugin(schema, defaultValue) {
122
117
  type: Boolean,
123
118
  },
124
119
  });
125
- function applyDeleteFilter(q) {
120
+ var applyDeleteFilter = function (q) {
126
121
  var query = q.getQuery();
127
122
  if (query && query.deleted === undefined) {
128
123
  void q.where({ deleted: { $ne: true } });
129
124
  }
130
- }
125
+ };
131
126
  schema.pre("find", function () {
132
127
  applyDeleteFilter(this);
133
128
  });
134
129
  schema.pre("findOne", function () {
135
130
  applyDeleteFilter(this);
136
131
  });
137
- }
138
- function isDisabledPlugin(schema, defaultValue) {
132
+ };
133
+ exports.isDeletedPlugin = isDeletedPlugin;
134
+ var isDisabledPlugin = function (schema, defaultValue) {
139
135
  if (defaultValue === void 0) { defaultValue = false; }
140
136
  schema.add({
141
137
  disabled: {
@@ -145,10 +141,13 @@ function isDisabledPlugin(schema, defaultValue) {
145
141
  type: Boolean,
146
142
  },
147
143
  });
148
- }
149
- function createdUpdatedPlugin(schema) {
150
- schema.add({ updated: { index: true, type: Date } });
151
- schema.add({ created: { index: true, type: Date } });
144
+ };
145
+ exports.isDisabledPlugin = isDisabledPlugin;
146
+ var createdUpdatedPlugin = function (schema) {
147
+ schema.add({
148
+ updated: { description: "When this document was last updated", index: true, type: Date },
149
+ });
150
+ schema.add({ created: { description: "When this document was created", index: true, type: Date } });
152
151
  schema.pre("save", function () {
153
152
  if (this.disableCreatedUpdatedPlugin === true) {
154
153
  return;
@@ -163,10 +162,14 @@ function createdUpdatedPlugin(schema) {
163
162
  schema.pre(/save|updateOne|insertMany/, function () {
164
163
  void this.updateOne({}, { $set: { updated: new Date() } });
165
164
  });
166
- }
167
- function firebaseJWTPlugin(schema) {
168
- schema.add({ firebaseId: { index: true, type: String } });
169
- }
165
+ };
166
+ exports.createdUpdatedPlugin = createdUpdatedPlugin;
167
+ var firebaseJWTPlugin = function (schema) {
168
+ schema.add({
169
+ firebaseId: { description: "The user's Firebase authentication ID", index: true, type: String },
170
+ });
171
+ };
172
+ exports.firebaseJWTPlugin = firebaseJWTPlugin;
170
173
  /**
171
174
  * This adds a static method `Model.findOneOrNone` to the schema. This should replace `Model.findOne` in most instances.
172
175
  * `Model.findOne` should only be used with a unique index, but that's not apparent from the docs. Otherwise you can wind
@@ -174,7 +177,7 @@ function firebaseJWTPlugin(schema) {
174
177
  * document, or throws an exception if multiple are found.
175
178
  * @param schema Mongoose Schema
176
179
  */
177
- function findOneOrNone(schema) {
180
+ var findOneOrNone = function (schema) {
178
181
  schema.statics.findOneOrNone = function (query, errorArgs) {
179
182
  return __awaiter(this, void 0, void 0, function () {
180
183
  var results;
@@ -194,7 +197,8 @@ function findOneOrNone(schema) {
194
197
  });
195
198
  });
196
199
  };
197
- }
200
+ };
201
+ exports.findOneOrNone = findOneOrNone;
198
202
  /**
199
203
  * This adds a static method `Model.findExactlyOne` to the schema. This or findOneOrNone should replace `Model.findOne`
200
204
  * in most instances.
@@ -203,7 +207,7 @@ function findOneOrNone(schema) {
203
207
  * multiple or none are found.
204
208
  * @param schema Mongoose Schema
205
209
  */
206
- function findExactlyOne(schema) {
210
+ var findExactlyOne = function (schema) {
207
211
  schema.statics.findExactlyOne = function (query, errorArgs) {
208
212
  return __awaiter(this, void 0, void 0, function () {
209
213
  var results;
@@ -223,14 +227,15 @@ function findExactlyOne(schema) {
223
227
  });
224
228
  });
225
229
  };
226
- }
230
+ };
231
+ exports.findExactlyOne = findExactlyOne;
227
232
  /**
228
233
  * This adds a static method `Model.upsert` to the schema. This method will either update an existing document
229
234
  * that matches the conditions or create a new document if none exists. It throws an error if multiple documents
230
235
  * match the conditions to prevent ambiguous updates.
231
236
  * @param schema Mongoose Schema
232
237
  */
233
- function upsertPlugin(schema) {
238
+ var upsertPlugin = function (schema) {
234
239
  schema.statics.upsert = function (conditions, update) {
235
240
  return __awaiter(this, void 0, void 0, function () {
236
241
  var docs, doc, combinedData, newDoc;
@@ -259,7 +264,8 @@ function upsertPlugin(schema) {
259
264
  });
260
265
  });
261
266
  };
262
- }
267
+ };
268
+ exports.upsertPlugin = upsertPlugin;
263
269
  var DateOnly = /** @class */ (function (_super) {
264
270
  __extends(DateOnly, _super);
265
271
  function DateOnly(key, options) {
@@ -1,4 +1,37 @@
1
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 () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -53,6 +86,7 @@ var __read = (this && this.__read) || function (o, n) {
53
86
  };
54
87
  Object.defineProperty(exports, "__esModule", { value: true });
55
88
  var bun_test_1 = require("bun:test");
89
+ var mongoose_1 = __importStar(require("mongoose"));
56
90
  var populate_1 = require("./populate");
57
91
  var tests_1 = require("./tests");
58
92
  (0, bun_test_1.describe)("populate functions", function () {
@@ -183,3 +217,68 @@ var tests_1 = require("./tests");
183
217
  (0, bun_test_1.expect)(result.containers[1].items).toEqual(["item-3", "item-4"]);
184
218
  });
185
219
  });
220
+ (0, bun_test_1.describe)("fixMixedFields", function () {
221
+ (0, bun_test_1.it)("returns early when schema is missing", function () {
222
+ var properties = { foo: { type: "object" } };
223
+ (0, bun_test_1.expect)(function () { return (0, populate_1.fixMixedFields)(null, properties); }).not.toThrow();
224
+ });
225
+ (0, bun_test_1.it)("returns early when properties is missing", function () {
226
+ var schema = new mongoose_1.Schema({});
227
+ (0, bun_test_1.expect)(function () { return (0, populate_1.fixMixedFields)(schema, null); }).not.toThrow();
228
+ });
229
+ (0, bun_test_1.it)("replaces Mixed fields with only description", function () {
230
+ var schema = new mongoose_1.Schema({ data: { description: "any data", type: mongoose_1.Schema.Types.Mixed } });
231
+ var properties = { data: { description: "any data", type: "object" } };
232
+ (0, populate_1.fixMixedFields)(schema, properties);
233
+ (0, bun_test_1.expect)(properties.data).toEqual({ description: "any data" });
234
+ });
235
+ (0, bun_test_1.it)("recurses into arrays of sub-documents", function () {
236
+ var subSchema = new mongoose_1.Schema({ meta: { type: mongoose_1.Schema.Types.Mixed } });
237
+ var schema = new mongoose_1.Schema({ items: [subSchema] });
238
+ var properties = {
239
+ items: {
240
+ items: {
241
+ properties: {
242
+ meta: { type: "object" },
243
+ },
244
+ },
245
+ type: "array",
246
+ },
247
+ };
248
+ (0, populate_1.fixMixedFields)(schema, properties);
249
+ (0, bun_test_1.expect)(properties.items.items.properties.meta).toEqual({ description: undefined });
250
+ });
251
+ (0, bun_test_1.it)("skips unknown paths", function () {
252
+ var schema = new mongoose_1.Schema({ foo: String });
253
+ var properties = { unknownKey: { type: "string" } };
254
+ (0, bun_test_1.expect)(function () { return (0, populate_1.fixMixedFields)(schema, properties); }).not.toThrow();
255
+ });
256
+ });
257
+ (0, bun_test_1.describe)("getOpenApiSpecForModel edge cases", function () {
258
+ (0, bun_test_1.it)("returns model properties without populatePaths", function () {
259
+ var result = (0, populate_1.getOpenApiSpecForModel)(tests_1.UserModel);
260
+ (0, bun_test_1.expect)(result.properties).toBeDefined();
261
+ });
262
+ (0, bun_test_1.it)("returns with extraModelProperties merged", function () {
263
+ var result = (0, populate_1.getOpenApiSpecForModel)(tests_1.UserModel, {
264
+ extraModelProperties: { customField: { type: "string" } },
265
+ });
266
+ (0, bun_test_1.expect)(result.properties.customField).toEqual({ type: "string" });
267
+ });
268
+ (0, bun_test_1.it)("skips populate paths without ref", function () {
269
+ // Create a schema with a non-referenced ObjectId field
270
+ var testSchema = new mongoose_1.Schema({ name: String, simpleId: mongoose_1.Schema.Types.ObjectId });
271
+ var TestModelNoRef = mongoose_1.default.models.TestModelNoRef || mongoose_1.default.model("TestModelNoRef", testSchema);
272
+ var result = (0, populate_1.getOpenApiSpecForModel)(TestModelNoRef, {
273
+ populatePaths: [{ path: "simpleId" }],
274
+ });
275
+ // Should not throw, simpleId stays as-is
276
+ (0, bun_test_1.expect)(result.properties).toBeDefined();
277
+ });
278
+ (0, bun_test_1.it)("populates with fields allowlist", function () {
279
+ var result = (0, populate_1.getOpenApiSpecForModel)(tests_1.FoodModel, {
280
+ populatePaths: [{ fields: ["name"], path: "ownerId" }],
281
+ });
282
+ (0, bun_test_1.expect)(result.properties).toBeDefined();
283
+ });
284
+ });
@@ -246,4 +246,277 @@ var baseDef = {
246
246
  }
247
247
  });
248
248
  }); });
249
+ (0, bun_test_1.it)("publishes new version when type changes", function () { return __awaiter(void 0, void 0, void 0, function () {
250
+ var updated, result;
251
+ return __generator(this, function (_a) {
252
+ switch (_a.label) {
253
+ case 0: return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: baseDef })];
254
+ case 1:
255
+ _a.sent();
256
+ updated = __assign(__assign({}, baseDef), { type: "privacy" });
257
+ return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: updated })];
258
+ case 2:
259
+ result = _a.sent();
260
+ (0, bun_test_1.expect)(result.updated).toEqual(["terms"]);
261
+ return [2 /*return*/];
262
+ }
263
+ });
264
+ }); });
265
+ (0, bun_test_1.it)("publishes new version when order changes", function () { return __awaiter(void 0, void 0, void 0, function () {
266
+ var updated, result;
267
+ return __generator(this, function (_a) {
268
+ switch (_a.label) {
269
+ case 0: return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: baseDef })];
270
+ case 1:
271
+ _a.sent();
272
+ updated = __assign(__assign({}, baseDef), { order: 99 });
273
+ return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: updated })];
274
+ case 2:
275
+ result = _a.sent();
276
+ (0, bun_test_1.expect)(result.updated).toEqual(["terms"]);
277
+ return [2 /*return*/];
278
+ }
279
+ });
280
+ }); });
281
+ (0, bun_test_1.it)("publishes new version when required changes", function () { return __awaiter(void 0, void 0, void 0, function () {
282
+ var updated, result;
283
+ return __generator(this, function (_a) {
284
+ switch (_a.label) {
285
+ case 0: return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: baseDef })];
286
+ case 1:
287
+ _a.sent();
288
+ updated = __assign(__assign({}, baseDef), { required: false });
289
+ return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: updated })];
290
+ case 2:
291
+ result = _a.sent();
292
+ (0, bun_test_1.expect)(result.updated).toEqual(["terms"]);
293
+ return [2 /*return*/];
294
+ }
295
+ });
296
+ }); });
297
+ (0, bun_test_1.it)("publishes new version when requireScrollToBottom changes", function () { return __awaiter(void 0, void 0, void 0, function () {
298
+ var updated, result;
299
+ return __generator(this, function (_a) {
300
+ switch (_a.label) {
301
+ case 0: return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: baseDef })];
302
+ case 1:
303
+ _a.sent();
304
+ updated = __assign(__assign({}, baseDef), { requireScrollToBottom: true });
305
+ return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: updated })];
306
+ case 2:
307
+ result = _a.sent();
308
+ (0, bun_test_1.expect)(result.updated).toEqual(["terms"]);
309
+ return [2 /*return*/];
310
+ }
311
+ });
312
+ }); });
313
+ (0, bun_test_1.it)("publishes new version when captureSignature changes", function () { return __awaiter(void 0, void 0, void 0, function () {
314
+ var updated, result;
315
+ return __generator(this, function (_a) {
316
+ switch (_a.label) {
317
+ case 0: return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: baseDef })];
318
+ case 1:
319
+ _a.sent();
320
+ updated = __assign(__assign({}, baseDef), { captureSignature: true });
321
+ return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: updated })];
322
+ case 2:
323
+ result = _a.sent();
324
+ (0, bun_test_1.expect)(result.updated).toEqual(["terms"]);
325
+ return [2 /*return*/];
326
+ }
327
+ });
328
+ }); });
329
+ (0, bun_test_1.it)("publishes new version when agreeButtonText changes", function () { return __awaiter(void 0, void 0, void 0, function () {
330
+ var updated, result;
331
+ return __generator(this, function (_a) {
332
+ switch (_a.label) {
333
+ case 0: return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: baseDef })];
334
+ case 1:
335
+ _a.sent();
336
+ updated = __assign(__assign({}, baseDef), { agreeButtonText: "Consent" });
337
+ return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: updated })];
338
+ case 2:
339
+ result = _a.sent();
340
+ (0, bun_test_1.expect)(result.updated).toEqual(["terms"]);
341
+ return [2 /*return*/];
342
+ }
343
+ });
344
+ }); });
345
+ (0, bun_test_1.it)("publishes new version when allowDecline changes", function () { return __awaiter(void 0, void 0, void 0, function () {
346
+ var updated, result;
347
+ return __generator(this, function (_a) {
348
+ switch (_a.label) {
349
+ case 0: return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: baseDef })];
350
+ case 1:
351
+ _a.sent();
352
+ updated = __assign(__assign({}, baseDef), { allowDecline: true });
353
+ return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: updated })];
354
+ case 2:
355
+ result = _a.sent();
356
+ (0, bun_test_1.expect)(result.updated).toEqual(["terms"]);
357
+ return [2 /*return*/];
358
+ }
359
+ });
360
+ }); });
361
+ (0, bun_test_1.it)("publishes new version when declineButtonText changes", function () { return __awaiter(void 0, void 0, void 0, function () {
362
+ var updated, result;
363
+ return __generator(this, function (_a) {
364
+ switch (_a.label) {
365
+ case 0: return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: baseDef })];
366
+ case 1:
367
+ _a.sent();
368
+ updated = __assign(__assign({}, baseDef), { allowDecline: true, declineButtonText: "No Thanks" });
369
+ return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: updated })];
370
+ case 2:
371
+ result = _a.sent();
372
+ (0, bun_test_1.expect)(result.updated).toEqual(["terms"]);
373
+ return [2 /*return*/];
374
+ }
375
+ });
376
+ }); });
377
+ (0, bun_test_1.it)("publishes new version when defaultLocale changes", function () { return __awaiter(void 0, void 0, void 0, function () {
378
+ var updated, result;
379
+ return __generator(this, function (_a) {
380
+ switch (_a.label) {
381
+ case 0: return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: baseDef })];
382
+ case 1:
383
+ _a.sent();
384
+ updated = __assign(__assign({}, baseDef), { defaultLocale: "es" });
385
+ return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: updated })];
386
+ case 2:
387
+ result = _a.sent();
388
+ (0, bun_test_1.expect)(result.updated).toEqual(["terms"]);
389
+ return [2 /*return*/];
390
+ }
391
+ });
392
+ }); });
393
+ (0, bun_test_1.it)("publishes new version when content locale count changes", function () { return __awaiter(void 0, void 0, void 0, function () {
394
+ var updated, result;
395
+ return __generator(this, function (_a) {
396
+ switch (_a.label) {
397
+ case 0: return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: baseDef })];
398
+ case 1:
399
+ _a.sent();
400
+ updated = __assign(__assign({}, baseDef), { content: { en: baseDef.content.en, es: "# Términos" } });
401
+ return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: updated })];
402
+ case 2:
403
+ result = _a.sent();
404
+ (0, bun_test_1.expect)(result.updated).toEqual(["terms"]);
405
+ return [2 /*return*/];
406
+ }
407
+ });
408
+ }); });
409
+ (0, bun_test_1.it)("publishes new version when checkbox count changes", function () { return __awaiter(void 0, void 0, void 0, function () {
410
+ var updated, result;
411
+ return __generator(this, function (_a) {
412
+ switch (_a.label) {
413
+ case 0: return [4 /*yield*/, (0, syncConsents_1.syncConsents)({
414
+ terms: __assign(__assign({}, baseDef), { checkboxes: [{ label: "Agree", required: true }] }),
415
+ })];
416
+ case 1:
417
+ _a.sent();
418
+ updated = __assign(__assign({}, baseDef), { checkboxes: [
419
+ { label: "Agree", required: true },
420
+ { label: "Also agree", required: false },
421
+ ] });
422
+ return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: updated })];
423
+ case 2:
424
+ result = _a.sent();
425
+ (0, bun_test_1.expect)(result.updated).toEqual(["terms"]);
426
+ return [2 /*return*/];
427
+ }
428
+ });
429
+ }); });
430
+ (0, bun_test_1.it)("publishes new version when checkbox label changes", function () { return __awaiter(void 0, void 0, void 0, function () {
431
+ var updated, result;
432
+ return __generator(this, function (_a) {
433
+ switch (_a.label) {
434
+ case 0: return [4 /*yield*/, (0, syncConsents_1.syncConsents)({
435
+ terms: __assign(__assign({}, baseDef), { checkboxes: [{ label: "Agree", required: true }] }),
436
+ })];
437
+ case 1:
438
+ _a.sent();
439
+ updated = __assign(__assign({}, baseDef), { checkboxes: [{ label: "I Agree", required: true }] });
440
+ return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: updated })];
441
+ case 2:
442
+ result = _a.sent();
443
+ (0, bun_test_1.expect)(result.updated).toEqual(["terms"]);
444
+ return [2 /*return*/];
445
+ }
446
+ });
447
+ }); });
448
+ (0, bun_test_1.it)("publishes new version when checkbox confirmationPrompt changes", function () { return __awaiter(void 0, void 0, void 0, function () {
449
+ var updated, result;
450
+ return __generator(this, function (_a) {
451
+ switch (_a.label) {
452
+ case 0: return [4 /*yield*/, (0, syncConsents_1.syncConsents)({
453
+ terms: __assign(__assign({}, baseDef), { checkboxes: [{ confirmationPrompt: "Sure?", label: "Agree", required: true }] }),
454
+ })];
455
+ case 1:
456
+ _a.sent();
457
+ updated = __assign(__assign({}, baseDef), { checkboxes: [{ confirmationPrompt: "Are you sure?", label: "Agree", required: true }] });
458
+ return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: updated })];
459
+ case 2:
460
+ result = _a.sent();
461
+ (0, bun_test_1.expect)(result.updated).toEqual(["terms"]);
462
+ return [2 /*return*/];
463
+ }
464
+ });
465
+ }); });
466
+ (0, bun_test_1.it)("leaves unchanged forms alone with checkboxes present", function () { return __awaiter(void 0, void 0, void 0, function () {
467
+ var withCheckboxes, result;
468
+ return __generator(this, function (_a) {
469
+ switch (_a.label) {
470
+ case 0:
471
+ withCheckboxes = __assign(__assign({}, baseDef), { checkboxes: [{ confirmationPrompt: "Sure?", label: "Agree", required: true }] });
472
+ return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: withCheckboxes })];
473
+ case 1:
474
+ _a.sent();
475
+ return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: withCheckboxes })];
476
+ case 2:
477
+ result = _a.sent();
478
+ (0, bun_test_1.expect)(result.unchanged).toEqual(["terms"]);
479
+ return [2 /*return*/];
480
+ }
481
+ });
482
+ }); });
483
+ (0, bun_test_1.it)("dry run does not create new versions", function () { return __awaiter(void 0, void 0, void 0, function () {
484
+ var updated, result, forms;
485
+ return __generator(this, function (_a) {
486
+ switch (_a.label) {
487
+ case 0: return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: baseDef })];
488
+ case 1:
489
+ _a.sent();
490
+ updated = __assign(__assign({}, baseDef), { title: "Updated" });
491
+ return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: updated }, { dryRun: true })];
492
+ case 2:
493
+ result = _a.sent();
494
+ (0, bun_test_1.expect)(result.updated).toEqual(["terms"]);
495
+ return [4 /*yield*/, consentForm_1.ConsentForm.find({ slug: "terms" })];
496
+ case 3:
497
+ forms = _a.sent();
498
+ (0, bun_test_1.expect)(forms).toHaveLength(1); // No new version created
499
+ return [2 /*return*/];
500
+ }
501
+ });
502
+ }); });
503
+ (0, bun_test_1.it)("dry run does not deactivate forms", function () { return __awaiter(void 0, void 0, void 0, function () {
504
+ var result, privacy;
505
+ return __generator(this, function (_a) {
506
+ switch (_a.label) {
507
+ case 0: return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ privacy: __assign(__assign({}, baseDef), { title: "Privacy", type: "privacy" }), terms: baseDef })];
508
+ case 1:
509
+ _a.sent();
510
+ return [4 /*yield*/, (0, syncConsents_1.syncConsents)({ terms: baseDef }, { deactivateRemoved: true, dryRun: true })];
511
+ case 2:
512
+ result = _a.sent();
513
+ (0, bun_test_1.expect)(result.deactivated).toEqual(["privacy"]);
514
+ return [4 /*yield*/, consentForm_1.ConsentForm.findOne({ slug: "privacy" })];
515
+ case 3:
516
+ privacy = _a.sent();
517
+ (0, bun_test_1.expect)(privacy === null || privacy === void 0 ? void 0 : privacy.active).toBe(true); // Still active
518
+ return [2 /*return*/];
519
+ }
520
+ });
521
+ }); });
249
522
  });
package/dist/tests.d.ts CHANGED
@@ -71,9 +71,9 @@ export declare const RequiredModel: mongoose.Model<RequiredField, {}, {}, {}, mo
71
71
  } & {
72
72
  __v: number;
73
73
  }, any>;
74
- export declare function getBaseServer(): Express;
75
- export declare function authAsUser(app: express.Application, type: "admin" | "notAdmin"): Promise<TestAgent>;
76
- export declare function setupDb(): Promise<(mongoose.Document<unknown, {}, User, {}, {}> & User & {
74
+ export declare const getBaseServer: () => Express;
75
+ export declare const authAsUser: (app: express.Application, type: "admin" | "notAdmin") => Promise<TestAgent>;
76
+ export declare const setupDb: () => Promise<(mongoose.Document<unknown, {}, User, {}, {}> & User & {
77
77
  _id: mongoose.Types.ObjectId;
78
78
  } & {
79
79
  __v: number;