@terreno/api 0.31.0 → 56.0.0-beta.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 (250) hide show
  1. package/CHANGELOG.md +122 -2
  2. package/LICENSE +202 -21
  3. package/dist/api.d.ts +12 -3
  4. package/dist/api.js +110 -361
  5. package/dist/auth.d.ts +26 -0
  6. package/dist/auth.js +100 -1
  7. package/dist/betterAuth.d.ts +5 -0
  8. package/dist/betterAuthSetup.d.ts +1 -15
  9. package/dist/betterAuthSetup.js +29 -8
  10. package/dist/configurationPlugin.js +2 -2
  11. package/dist/docLoader.js +12 -9
  12. package/dist/errors.d.ts +13 -0
  13. package/dist/errors.js +29 -1
  14. package/dist/expressServer.js +5 -11
  15. package/dist/githubAuth.js +4 -1
  16. package/dist/index.d.ts +17 -1
  17. package/dist/index.js +29 -1
  18. package/dist/middleware.d.ts +7 -0
  19. package/dist/middleware.js +16 -1
  20. package/dist/openApiCompat.d.ts +10 -1
  21. package/dist/openApiCompat.js +115 -47
  22. package/dist/permissions.d.ts +27 -0
  23. package/dist/permissions.js +42 -1
  24. package/dist/plugins.d.ts +15 -3
  25. package/dist/plugins.js +36 -6
  26. package/dist/realtime/changeStreamWatcher.d.ts +100 -3
  27. package/dist/realtime/changeStreamWatcher.js +542 -137
  28. package/dist/realtime/realtimeApp.d.ts +3 -1
  29. package/dist/realtime/realtimeApp.js +75 -27
  30. package/dist/realtime/sessionRevalidation.d.ts +90 -0
  31. package/dist/realtime/sessionRevalidation.js +438 -0
  32. package/dist/realtime/socketAuth.d.ts +97 -0
  33. package/dist/realtime/socketAuth.js +272 -0
  34. package/dist/realtime/socketUser.d.ts +54 -0
  35. package/dist/realtime/socketUser.js +75 -5
  36. package/dist/realtime/types.d.ts +40 -0
  37. package/dist/secretProviders.d.ts +23 -0
  38. package/dist/secretProviders.js +9 -3
  39. package/dist/sync/executors.d.ts +198 -0
  40. package/dist/sync/executors.js +670 -0
  41. package/dist/sync/loadHarness.js +807 -0
  42. package/dist/sync/models.d.ts +216 -0
  43. package/dist/sync/models.js +644 -0
  44. package/dist/sync/mutationHandler.d.ts +97 -0
  45. package/dist/sync/mutationHandler.js +886 -0
  46. package/dist/sync/registry.d.ts +73 -0
  47. package/dist/sync/registry.js +223 -0
  48. package/dist/sync/routes.d.ts +62 -0
  49. package/dist/sync/routes.js +936 -0
  50. package/dist/sync/scripts/compactTombstones.d.ts +47 -0
  51. package/dist/sync/scripts/compactTombstones.js +270 -0
  52. package/dist/sync/serialize.d.ts +20 -0
  53. package/dist/{tests/bunSetup.js → sync/serialize.js} +35 -68
  54. package/dist/sync/socketHandlers.d.ts +54 -0
  55. package/dist/sync/socketHandlers.js +470 -0
  56. package/dist/sync/streams.d.ts +85 -0
  57. package/dist/sync/streams.js +221 -0
  58. package/dist/sync/syncApp.d.ts +29 -0
  59. package/dist/sync/syncApp.js +44 -0
  60. package/dist/sync/syncBatch.d.ts +71 -0
  61. package/dist/sync/syncBatch.js +252 -0
  62. package/dist/sync/syncSeqPlugin.d.ts +8 -0
  63. package/dist/sync/syncSeqPlugin.js +903 -0
  64. package/dist/sync/types.d.ts +254 -0
  65. package/dist/sync/types.js +9 -0
  66. package/dist/terrenoApp.js +90 -27
  67. package/dist/tests/models.d.ts +11 -27
  68. package/dist/tests/models.js +3 -5
  69. package/dist/tests/testHelper.d.ts +3 -9
  70. package/dist/vendor/wesleytodd-openapi/index.d.ts +1 -1
  71. package/dist/vendor/wesleytodd-openapi/lib/ui.d.ts +2 -1
  72. package/package.json +10 -8
  73. package/src/__tests__/openApiCompat.test.ts +20 -0
  74. package/src/actions.test.ts +12 -19
  75. package/src/actions.ts +2 -2
  76. package/src/api.coverage.test.ts +9 -7
  77. package/src/api.errorPaths.test.ts +1 -47
  78. package/src/api.test.ts +12 -0
  79. package/src/api.ts +98 -317
  80. package/src/auth.test.ts +128 -176
  81. package/src/auth.ts +109 -0
  82. package/src/betterAuth.ts +6 -0
  83. package/src/betterAuthSetup.test.ts +34 -0
  84. package/src/betterAuthSetup.ts +27 -8
  85. package/src/configurationPlugin.ts +2 -2
  86. package/src/consentApp.test.ts +12 -12
  87. package/src/docLoader.ts +3 -1
  88. package/src/errors.ts +33 -0
  89. package/src/expressServer.test.ts +7 -1
  90. package/src/expressServer.ts +5 -11
  91. package/src/githubAuth.ts +3 -1
  92. package/src/index.ts +42 -0
  93. package/src/middleware.test.ts +40 -1
  94. package/src/middleware.ts +15 -0
  95. package/src/models/versionConfig.ts +1 -1
  96. package/src/openApiBuilder.test.ts +9 -24
  97. package/src/openApiCompat.ts +99 -45
  98. package/src/openApiValidator.test.ts +0 -41
  99. package/src/permissions.test.ts +75 -1
  100. package/src/permissions.ts +49 -0
  101. package/src/plugins.test.ts +54 -14
  102. package/src/plugins.ts +47 -9
  103. package/src/populate.test.ts +16 -25
  104. package/src/realtime/changeStreamWatcher.ts +552 -114
  105. package/src/realtime/realtime.test.ts +157 -239
  106. package/src/realtime/realtimeApp.ts +80 -19
  107. package/src/realtime/sessionRevalidation.test.ts +423 -0
  108. package/src/realtime/sessionRevalidation.ts +273 -0
  109. package/src/realtime/socketAuth.test.ts +355 -0
  110. package/src/realtime/socketAuth.ts +228 -0
  111. package/src/realtime/socketUser.ts +69 -0
  112. package/src/realtime/types.ts +40 -0
  113. package/src/secretProviders.test.ts +7 -1
  114. package/src/secretProviders.ts +15 -3
  115. package/src/sync/ensureSyncIndexes.test.ts +144 -0
  116. package/src/sync/executors.test.ts +882 -0
  117. package/src/sync/executors.ts +703 -0
  118. package/src/sync/integration.test.ts +1160 -0
  119. package/src/sync/loadHarness.ts +618 -0
  120. package/src/sync/models.ts +640 -0
  121. package/src/sync/mutationHandler.test.ts +1252 -0
  122. package/src/sync/mutationHandler.ts +850 -0
  123. package/src/sync/registry.ts +232 -0
  124. package/src/sync/routes.ts +812 -0
  125. package/src/sync/scripts/compactTombstones.test.ts +249 -0
  126. package/src/sync/scripts/compactTombstones.ts +145 -0
  127. package/src/sync/serialize.ts +48 -0
  128. package/src/sync/sessionRevalidationIntegration.test.ts +281 -0
  129. package/src/sync/socketHandlers.ts +320 -0
  130. package/src/sync/streams.ts +188 -0
  131. package/src/sync/sync.test.ts +582 -0
  132. package/src/sync/syncApp.ts +44 -0
  133. package/src/sync/syncBatch.ts +219 -0
  134. package/src/sync/syncFrontier.test.ts +494 -0
  135. package/src/sync/syncPhaseC.test.ts +718 -0
  136. package/src/sync/syncRoutes.test.ts +865 -0
  137. package/src/sync/syncSeqPlugin.ts +738 -0
  138. package/src/sync/syncSocket.test.ts +1440 -0
  139. package/src/sync/types.ts +270 -0
  140. package/src/terrenoApp.ts +37 -17
  141. package/src/tests/bunSetup.ts +8 -0
  142. package/src/tests/models.ts +6 -8
  143. package/tsconfig.json +4 -4
  144. package/tsconfig.typedoc.json +7 -1
  145. package/dist/__tests__/openApiCompat.test.js +0 -317
  146. package/dist/__tests__/versionCheckPlugin.test.d.ts +0 -1
  147. package/dist/__tests__/versionCheckPlugin.test.js +0 -597
  148. package/dist/actions.openApi.test.d.ts +0 -1
  149. package/dist/actions.openApi.test.js +0 -253
  150. package/dist/actions.test.d.ts +0 -1
  151. package/dist/actions.test.js +0 -1087
  152. package/dist/api.arrayOperations.test.d.ts +0 -1
  153. package/dist/api.arrayOperations.test.js +0 -878
  154. package/dist/api.asyncHandler.test.d.ts +0 -1
  155. package/dist/api.asyncHandler.test.js +0 -236
  156. package/dist/api.coverage.test.d.ts +0 -1
  157. package/dist/api.coverage.test.js +0 -192
  158. package/dist/api.errorPaths.test.d.ts +0 -1
  159. package/dist/api.errorPaths.test.js +0 -887
  160. package/dist/api.errors.test.d.ts +0 -1
  161. package/dist/api.errors.test.js +0 -185
  162. package/dist/api.hooks.test.d.ts +0 -1
  163. package/dist/api.hooks.test.js +0 -950
  164. package/dist/api.query.test.d.ts +0 -1
  165. package/dist/api.query.test.js +0 -948
  166. package/dist/api.test.d.ts +0 -1
  167. package/dist/api.test.js +0 -2820
  168. package/dist/auth.compile.test.d.ts +0 -1
  169. package/dist/auth.compile.test.js +0 -201
  170. package/dist/auth.coverage.test.d.ts +0 -1
  171. package/dist/auth.coverage.test.js +0 -202
  172. package/dist/auth.test.d.ts +0 -1
  173. package/dist/auth.test.js +0 -2286
  174. package/dist/betterAuth.test.d.ts +0 -1
  175. package/dist/betterAuth.test.js +0 -181
  176. package/dist/betterAuthApp.test.d.ts +0 -1
  177. package/dist/betterAuthApp.test.js +0 -242
  178. package/dist/betterAuthSetup.test.d.ts +0 -1
  179. package/dist/betterAuthSetup.test.js +0 -762
  180. package/dist/config.test.d.ts +0 -1
  181. package/dist/config.test.js +0 -353
  182. package/dist/configuration.test.d.ts +0 -1
  183. package/dist/configuration.test.js +0 -980
  184. package/dist/configurationPlugin.test.d.ts +0 -1
  185. package/dist/configurationPlugin.test.js +0 -827
  186. package/dist/consentApp.test.d.ts +0 -1
  187. package/dist/consentApp.test.js +0 -1411
  188. package/dist/docLoader.test.d.ts +0 -1
  189. package/dist/docLoader.test.js +0 -137
  190. package/dist/envConfigurationPlugin.test.d.ts +0 -1
  191. package/dist/envConfigurationPlugin.test.js +0 -369
  192. package/dist/errors.test.d.ts +0 -1
  193. package/dist/errors.test.js +0 -607
  194. package/dist/expressServer.test.d.ts +0 -1
  195. package/dist/expressServer.test.js +0 -1249
  196. package/dist/githubAuth.test.d.ts +0 -1
  197. package/dist/githubAuth.test.js +0 -1142
  198. package/dist/httpClient.test.d.ts +0 -1
  199. package/dist/httpClient.test.js +0 -1471
  200. package/dist/logger.test.d.ts +0 -1
  201. package/dist/logger.test.js +0 -685
  202. package/dist/middleware.test.d.ts +0 -1
  203. package/dist/middleware.test.js +0 -241
  204. package/dist/notifiers/googleChatNotifier.test.d.ts +0 -1
  205. package/dist/notifiers/googleChatNotifier.test.js +0 -298
  206. package/dist/notifiers/slackNotifier.test.d.ts +0 -1
  207. package/dist/notifiers/slackNotifier.test.js +0 -297
  208. package/dist/notifiers/zoomNotifier.test.d.ts +0 -1
  209. package/dist/notifiers/zoomNotifier.test.js +0 -373
  210. package/dist/openApi.test.d.ts +0 -1
  211. package/dist/openApi.test.js +0 -620
  212. package/dist/openApiBuilder.test.d.ts +0 -1
  213. package/dist/openApiBuilder.test.js +0 -599
  214. package/dist/openApiEtag.test.d.ts +0 -1
  215. package/dist/openApiEtag.test.js +0 -86
  216. package/dist/openApiValidator.test.d.ts +0 -1
  217. package/dist/openApiValidator.test.js +0 -795
  218. package/dist/permissions.middleware.test.d.ts +0 -1
  219. package/dist/permissions.middleware.test.js +0 -308
  220. package/dist/permissions.test.d.ts +0 -1
  221. package/dist/permissions.test.js +0 -439
  222. package/dist/plugins.test.d.ts +0 -1
  223. package/dist/plugins.test.js +0 -902
  224. package/dist/populate.test.d.ts +0 -1
  225. package/dist/populate.test.js +0 -370
  226. package/dist/realtime/realtime.test.d.ts +0 -10
  227. package/dist/realtime/realtime.test.js +0 -4213
  228. package/dist/realtime/realtimeAppSetup.test.d.ts +0 -1
  229. package/dist/realtime/realtimeAppSetup.test.js +0 -213
  230. package/dist/requestContext.test.d.ts +0 -1
  231. package/dist/requestContext.test.js +0 -412
  232. package/dist/scriptRunner.test.d.ts +0 -1
  233. package/dist/scriptRunner.test.js +0 -386
  234. package/dist/secretProviders.test.d.ts +0 -1
  235. package/dist/secretProviders.test.js +0 -726
  236. package/dist/syncConsents.test.d.ts +0 -1
  237. package/dist/syncConsents.test.js +0 -522
  238. package/dist/terrenoApp.test.d.ts +0 -1
  239. package/dist/terrenoApp.test.js +0 -489
  240. package/dist/tests/bunSetup.d.ts +0 -1
  241. package/dist/tests/fixtures/compileAuthEntry.d.ts +0 -1
  242. package/dist/tests/fixtures/compileAuthEntry.js +0 -37
  243. package/dist/tests/testEnv.d.ts +0 -0
  244. package/dist/tests/testEnv.js +0 -6
  245. package/dist/transformers.test.d.ts +0 -1
  246. package/dist/transformers.test.js +0 -423
  247. package/dist/utils.test.d.ts +0 -1
  248. package/dist/utils.test.js +0 -242
  249. package/src/realtime/realtimeAppSetup.test.ts +0 -161
  250. /package/dist/{__tests__/openApiCompat.test.d.ts → sync/loadHarness.d.ts} +0 -0
@@ -1,1411 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __read = (this && this.__read) || function (o, n) {
39
- var m = typeof Symbol === "function" && o[Symbol.iterator];
40
- if (!m) return o;
41
- var i = m.call(o), r, ar = [], e;
42
- try {
43
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
44
- }
45
- catch (error) { e = { error: error }; }
46
- finally {
47
- try {
48
- if (r && !r.done && (m = i["return"])) m.call(i);
49
- }
50
- finally { if (e) throw e.error; }
51
- }
52
- return ar;
53
- };
54
- var __importDefault = (this && this.__importDefault) || function (mod) {
55
- return (mod && mod.__esModule) ? mod : { "default": mod };
56
- };
57
- Object.defineProperty(exports, "__esModule", { value: true });
58
- var bun_test_1 = require("bun:test");
59
- var supertest_1 = __importDefault(require("supertest"));
60
- var consentApp_1 = require("./consentApp");
61
- var consentForm_1 = require("./models/consentForm");
62
- var consentResponse_1 = require("./models/consentResponse");
63
- var terrenoApp_1 = require("./terrenoApp");
64
- var tests_1 = require("./tests");
65
- var buildApp = function (consentAppOptions) {
66
- if (consentAppOptions === void 0) { consentAppOptions = {}; }
67
- return new terrenoApp_1.TerrenoApp({
68
- skipListen: true,
69
- userModel: tests_1.UserModel,
70
- })
71
- .register(new consentApp_1.ConsentApp(consentAppOptions))
72
- .build();
73
- };
74
- (0, bun_test_1.describe)("ConsentApp", function () {
75
- var admin;
76
- var notAdmin;
77
- var adminAgent;
78
- var userAgent;
79
- (0, bun_test_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
80
- var app;
81
- var _a;
82
- return __generator(this, function (_b) {
83
- switch (_b.label) {
84
- case 0: return [4 /*yield*/, (0, tests_1.setupDb)()];
85
- case 1:
86
- _a = __read.apply(void 0, [_b.sent(), 2]), admin = _a[0], notAdmin = _a[1];
87
- return [4 /*yield*/, Promise.all([consentForm_1.ConsentForm.deleteMany({}), consentResponse_1.ConsentResponse.deleteMany({})])];
88
- case 2:
89
- _b.sent();
90
- app = buildApp({ auditTrail: true });
91
- return [4 /*yield*/, (0, tests_1.authAsUser)(app, "admin")];
92
- case 3:
93
- adminAgent = _b.sent();
94
- return [4 /*yield*/, (0, tests_1.authAsUser)(app, "notAdmin")];
95
- case 4:
96
- userAgent = _b.sent();
97
- return [2 /*return*/];
98
- }
99
- });
100
- }); });
101
- (0, bun_test_1.afterEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
102
- return __generator(this, function (_a) {
103
- switch (_a.label) {
104
- case 0: return [4 /*yield*/, Promise.all([consentForm_1.ConsentForm.deleteMany({}), consentResponse_1.ConsentResponse.deleteMany({})])];
105
- case 1:
106
- _a.sent();
107
- return [2 /*return*/];
108
- }
109
- });
110
- }); });
111
- (0, bun_test_1.describe)("GET /consent-forms (admin CRUD)", function () {
112
- (0, bun_test_1.it)("returns empty list when no forms exist", function () { return __awaiter(void 0, void 0, void 0, function () {
113
- var res;
114
- return __generator(this, function (_a) {
115
- switch (_a.label) {
116
- case 0: return [4 /*yield*/, adminAgent.get("/consent-forms").expect(200)];
117
- case 1:
118
- res = _a.sent();
119
- (0, bun_test_1.expect)(res.body.data).toHaveLength(0);
120
- (0, bun_test_1.expect)(res.body.requestId).toBe(res.headers["x-request-id"]);
121
- return [2 /*return*/];
122
- }
123
- });
124
- }); });
125
- (0, bun_test_1.it)("lists consent forms for admins", function () { return __awaiter(void 0, void 0, void 0, function () {
126
- var res;
127
- return __generator(this, function (_a) {
128
- switch (_a.label) {
129
- case 0: return [4 /*yield*/, consentForm_1.ConsentForm.create({
130
- active: true,
131
- content: new Map([["en", "# Terms\nPlease agree."]]),
132
- order: 1,
133
- slug: "terms",
134
- title: "Terms of Service",
135
- type: "terms",
136
- version: 1,
137
- })];
138
- case 1:
139
- _a.sent();
140
- return [4 /*yield*/, adminAgent.get("/consent-forms").expect(200)];
141
- case 2:
142
- res = _a.sent();
143
- (0, bun_test_1.expect)(res.body.data).toHaveLength(1);
144
- (0, bun_test_1.expect)(res.body.data[0].title).toBe("Terms of Service");
145
- return [2 /*return*/];
146
- }
147
- });
148
- }); });
149
- (0, bun_test_1.it)("blocks non-admins from listing forms", function () { return __awaiter(void 0, void 0, void 0, function () {
150
- return __generator(this, function (_a) {
151
- switch (_a.label) {
152
- case 0: return [4 /*yield*/, userAgent.get("/consent-forms").expect(405)];
153
- case 1:
154
- _a.sent();
155
- return [2 /*return*/];
156
- }
157
- });
158
- }); });
159
- (0, bun_test_1.it)("creates a consent form as admin", function () { return __awaiter(void 0, void 0, void 0, function () {
160
- var res;
161
- return __generator(this, function (_a) {
162
- switch (_a.label) {
163
- case 0: return [4 /*yield*/, adminAgent
164
- .post("/consent-forms")
165
- .send({
166
- active: false,
167
- content: { en: "# Privacy\nWe protect your data." },
168
- order: 2,
169
- slug: "privacy",
170
- title: "Privacy Policy",
171
- type: "privacy",
172
- version: 1,
173
- })
174
- .expect(201)];
175
- case 1:
176
- res = _a.sent();
177
- (0, bun_test_1.expect)(res.body.data.title).toBe("Privacy Policy");
178
- (0, bun_test_1.expect)(res.body.data.slug).toBe("privacy");
179
- return [2 /*return*/];
180
- }
181
- });
182
- }); });
183
- (0, bun_test_1.it)("updates a consent form as admin", function () { return __awaiter(void 0, void 0, void 0, function () {
184
- var form, res;
185
- return __generator(this, function (_a) {
186
- switch (_a.label) {
187
- case 0: return [4 /*yield*/, consentForm_1.ConsentForm.create({
188
- active: false,
189
- content: new Map([["en", "# HIPAA"]]),
190
- order: 3,
191
- slug: "hipaa",
192
- title: "HIPAA Notice",
193
- type: "hipaa",
194
- version: 1,
195
- })];
196
- case 1:
197
- form = _a.sent();
198
- return [4 /*yield*/, adminAgent
199
- .patch("/consent-forms/".concat(form._id))
200
- .send({ title: "HIPAA Authorization" })
201
- .expect(200)];
202
- case 2:
203
- res = _a.sent();
204
- (0, bun_test_1.expect)(res.body.data.title).toBe("HIPAA Authorization");
205
- return [2 /*return*/];
206
- }
207
- });
208
- }); });
209
- });
210
- (0, bun_test_1.describe)("POST /consent-forms/:id/publish", function () {
211
- (0, bun_test_1.it)("creates a new version and activates it", function () { return __awaiter(void 0, void 0, void 0, function () {
212
- var form, res, oldForm;
213
- return __generator(this, function (_a) {
214
- switch (_a.label) {
215
- case 0: return [4 /*yield*/, consentForm_1.ConsentForm.create({
216
- active: true,
217
- content: new Map([["en", "# Terms v1"]]),
218
- order: 1,
219
- slug: "terms-publish",
220
- title: "Terms v1",
221
- type: "terms",
222
- version: 1,
223
- })];
224
- case 1:
225
- form = _a.sent();
226
- return [4 /*yield*/, adminAgent.post("/consent-forms/".concat(form._id, "/publish")).expect(200)];
227
- case 2:
228
- res = _a.sent();
229
- (0, bun_test_1.expect)(res.body.data.version).toBe(2);
230
- (0, bun_test_1.expect)(res.body.data.active).toBe(true);
231
- (0, bun_test_1.expect)(res.body.data.slug).toBe("terms-publish");
232
- return [4 /*yield*/, consentForm_1.ConsentForm.findById(form._id)];
233
- case 3:
234
- oldForm = _a.sent();
235
- (0, bun_test_1.expect)(oldForm === null || oldForm === void 0 ? void 0 : oldForm.active).toBe(false);
236
- return [2 /*return*/];
237
- }
238
- });
239
- }); });
240
- (0, bun_test_1.it)("increments version number correctly", function () { return __awaiter(void 0, void 0, void 0, function () {
241
- var form, res;
242
- return __generator(this, function (_a) {
243
- switch (_a.label) {
244
- case 0: return [4 /*yield*/, consentForm_1.ConsentForm.create({
245
- active: true,
246
- content: new Map([["en", "# Content"]]),
247
- order: 1,
248
- slug: "versioned",
249
- title: "Versioned Form",
250
- type: "agreement",
251
- version: 3,
252
- })];
253
- case 1:
254
- form = _a.sent();
255
- return [4 /*yield*/, adminAgent.post("/consent-forms/".concat(form._id, "/publish")).expect(200)];
256
- case 2:
257
- res = _a.sent();
258
- (0, bun_test_1.expect)(res.body.data.version).toBe(4);
259
- return [2 /*return*/];
260
- }
261
- });
262
- }); });
263
- (0, bun_test_1.it)("requires admin to publish", function () { return __awaiter(void 0, void 0, void 0, function () {
264
- var form;
265
- return __generator(this, function (_a) {
266
- switch (_a.label) {
267
- case 0: return [4 /*yield*/, consentForm_1.ConsentForm.create({
268
- active: true,
269
- content: new Map([["en", "# Terms"]]),
270
- order: 1,
271
- slug: "terms-nonadmin",
272
- title: "Terms",
273
- type: "terms",
274
- version: 1,
275
- })];
276
- case 1:
277
- form = _a.sent();
278
- return [4 /*yield*/, userAgent.post("/consent-forms/".concat(form._id, "/publish")).expect(403)];
279
- case 2:
280
- _a.sent();
281
- return [2 /*return*/];
282
- }
283
- });
284
- }); });
285
- });
286
- (0, bun_test_1.describe)("GET /consent-responses (admin read-only)", function () {
287
- (0, bun_test_1.it)("returns empty list when no responses", function () { return __awaiter(void 0, void 0, void 0, function () {
288
- var res;
289
- return __generator(this, function (_a) {
290
- switch (_a.label) {
291
- case 0: return [4 /*yield*/, adminAgent.get("/consent-responses").expect(200)];
292
- case 1:
293
- res = _a.sent();
294
- (0, bun_test_1.expect)(res.body.data).toHaveLength(0);
295
- return [2 /*return*/];
296
- }
297
- });
298
- }); });
299
- (0, bun_test_1.it)("lists responses for admins", function () { return __awaiter(void 0, void 0, void 0, function () {
300
- var form, res;
301
- return __generator(this, function (_a) {
302
- switch (_a.label) {
303
- case 0: return [4 /*yield*/, consentForm_1.ConsentForm.create({
304
- active: true,
305
- content: new Map([["en", "# Terms"]]),
306
- order: 1,
307
- slug: "terms-resp",
308
- title: "Terms",
309
- type: "terms",
310
- version: 1,
311
- })];
312
- case 1:
313
- form = _a.sent();
314
- return [4 /*yield*/, consentResponse_1.ConsentResponse.create({
315
- agreed: true,
316
- agreedAt: new Date(),
317
- consentFormId: form._id,
318
- formVersionSnapshot: 1,
319
- locale: "en",
320
- userId: notAdmin._id,
321
- })];
322
- case 2:
323
- _a.sent();
324
- return [4 /*yield*/, adminAgent.get("/consent-responses").expect(200)];
325
- case 3:
326
- res = _a.sent();
327
- (0, bun_test_1.expect)(res.body.data).toHaveLength(1);
328
- (0, bun_test_1.expect)(res.body.data[0].agreed).toBe(true);
329
- return [2 /*return*/];
330
- }
331
- });
332
- }); });
333
- (0, bun_test_1.it)("populates consentFormId and userId on read", function () { return __awaiter(void 0, void 0, void 0, function () {
334
- var form, response, res;
335
- return __generator(this, function (_a) {
336
- switch (_a.label) {
337
- case 0: return [4 /*yield*/, consentForm_1.ConsentForm.create({
338
- active: true,
339
- content: new Map([["en", "# Terms"]]),
340
- order: 1,
341
- slug: "terms-populated",
342
- title: "Terms Populated",
343
- type: "terms",
344
- version: 1,
345
- })];
346
- case 1:
347
- form = _a.sent();
348
- return [4 /*yield*/, consentResponse_1.ConsentResponse.create({
349
- agreed: true,
350
- agreedAt: new Date(),
351
- consentFormId: form._id,
352
- formVersionSnapshot: 1,
353
- locale: "en",
354
- userId: notAdmin._id,
355
- })];
356
- case 2:
357
- response = _a.sent();
358
- return [4 /*yield*/, adminAgent.get("/consent-responses/".concat(response._id)).expect(200)];
359
- case 3:
360
- res = _a.sent();
361
- (0, bun_test_1.expect)(res.body.data.consentFormId.title).toBe("Terms Populated");
362
- (0, bun_test_1.expect)(res.body.data.userId.email).toBe(notAdmin.email);
363
- (0, bun_test_1.expect)(res.body.data.userId.name).toBe(notAdmin.name);
364
- return [2 /*return*/];
365
- }
366
- });
367
- }); });
368
- (0, bun_test_1.it)("blocks non-admins from listing responses", function () { return __awaiter(void 0, void 0, void 0, function () {
369
- return __generator(this, function (_a) {
370
- switch (_a.label) {
371
- case 0: return [4 /*yield*/, userAgent.get("/consent-responses").expect(405)];
372
- case 1:
373
- _a.sent();
374
- return [2 /*return*/];
375
- }
376
- });
377
- }); });
378
- (0, bun_test_1.it)("blocks create on consent-responses", function () { return __awaiter(void 0, void 0, void 0, function () {
379
- return __generator(this, function (_a) {
380
- switch (_a.label) {
381
- case 0: return [4 /*yield*/, adminAgent.post("/consent-responses").send({}).expect(405)];
382
- case 1:
383
- _a.sent();
384
- return [2 /*return*/];
385
- }
386
- });
387
- }); });
388
- });
389
- (0, bun_test_1.describe)("GET /consents/pending", function () {
390
- (0, bun_test_1.it)("returns empty array when no active forms", function () { return __awaiter(void 0, void 0, void 0, function () {
391
- var res;
392
- return __generator(this, function (_a) {
393
- switch (_a.label) {
394
- case 0: return [4 /*yield*/, userAgent.get("/consents/pending").expect(200)];
395
- case 1:
396
- res = _a.sent();
397
- (0, bun_test_1.expect)(res.body.data).toHaveLength(0);
398
- return [2 /*return*/];
399
- }
400
- });
401
- }); });
402
- (0, bun_test_1.it)("returns active forms the user hasn't responded to", function () { return __awaiter(void 0, void 0, void 0, function () {
403
- var res;
404
- return __generator(this, function (_a) {
405
- switch (_a.label) {
406
- case 0: return [4 /*yield*/, consentForm_1.ConsentForm.create({
407
- active: true,
408
- content: new Map([["en", "# Terms"]]),
409
- order: 1,
410
- slug: "pending-terms",
411
- title: "Terms",
412
- type: "terms",
413
- version: 1,
414
- })];
415
- case 1:
416
- _a.sent();
417
- return [4 /*yield*/, userAgent.get("/consents/pending").expect(200)];
418
- case 2:
419
- res = _a.sent();
420
- (0, bun_test_1.expect)(res.body.data).toHaveLength(1);
421
- (0, bun_test_1.expect)(res.body.data[0].title).toBe("Terms");
422
- return [2 /*return*/];
423
- }
424
- });
425
- }); });
426
- (0, bun_test_1.it)("excludes forms the user has already responded to at the current version", function () { return __awaiter(void 0, void 0, void 0, function () {
427
- var form, res;
428
- return __generator(this, function (_a) {
429
- switch (_a.label) {
430
- case 0: return [4 /*yield*/, consentForm_1.ConsentForm.create({
431
- active: true,
432
- content: new Map([["en", "# Terms"]]),
433
- order: 1,
434
- slug: "responded-terms",
435
- title: "Terms",
436
- type: "terms",
437
- version: 1,
438
- })];
439
- case 1:
440
- form = _a.sent();
441
- return [4 /*yield*/, consentResponse_1.ConsentResponse.create({
442
- agreed: true,
443
- agreedAt: new Date(),
444
- consentFormId: form._id,
445
- formVersionSnapshot: 1,
446
- locale: "en",
447
- userId: notAdmin._id,
448
- })];
449
- case 2:
450
- _a.sent();
451
- return [4 /*yield*/, userAgent.get("/consents/pending").expect(200)];
452
- case 3:
453
- res = _a.sent();
454
- (0, bun_test_1.expect)(res.body.data).toHaveLength(0);
455
- return [2 /*return*/];
456
- }
457
- });
458
- }); });
459
- (0, bun_test_1.it)("includes forms when the user responded to an older version", function () { return __awaiter(void 0, void 0, void 0, function () {
460
- var form, res;
461
- return __generator(this, function (_a) {
462
- switch (_a.label) {
463
- case 0: return [4 /*yield*/, consentForm_1.ConsentForm.create({
464
- active: true,
465
- content: new Map([["en", "# Terms v2"]]),
466
- order: 1,
467
- slug: "updated-terms",
468
- title: "Terms",
469
- type: "terms",
470
- version: 2,
471
- })];
472
- case 1:
473
- form = _a.sent();
474
- // User responded to version 1
475
- return [4 /*yield*/, consentResponse_1.ConsentResponse.create({
476
- agreed: true,
477
- agreedAt: new Date(),
478
- consentFormId: form._id,
479
- formVersionSnapshot: 1,
480
- locale: "en",
481
- userId: notAdmin._id,
482
- })];
483
- case 2:
484
- // User responded to version 1
485
- _a.sent();
486
- return [4 /*yield*/, userAgent.get("/consents/pending").expect(200)];
487
- case 3:
488
- res = _a.sent();
489
- (0, bun_test_1.expect)(res.body.data).toHaveLength(1);
490
- return [2 /*return*/];
491
- }
492
- });
493
- }); });
494
- (0, bun_test_1.it)("returns forms sorted by order field", function () { return __awaiter(void 0, void 0, void 0, function () {
495
- var res;
496
- return __generator(this, function (_a) {
497
- switch (_a.label) {
498
- case 0: return [4 /*yield*/, Promise.all([
499
- consentForm_1.ConsentForm.create({
500
- active: true,
501
- content: new Map([["en", "# Second"]]),
502
- order: 2,
503
- slug: "second-form",
504
- title: "Second Form",
505
- type: "privacy",
506
- version: 1,
507
- }),
508
- consentForm_1.ConsentForm.create({
509
- active: true,
510
- content: new Map([["en", "# First"]]),
511
- order: 1,
512
- slug: "first-form",
513
- title: "First Form",
514
- type: "terms",
515
- version: 1,
516
- }),
517
- ])];
518
- case 1:
519
- _a.sent();
520
- return [4 /*yield*/, userAgent.get("/consents/pending").expect(200)];
521
- case 2:
522
- res = _a.sent();
523
- (0, bun_test_1.expect)(res.body.data).toHaveLength(2);
524
- (0, bun_test_1.expect)(res.body.data[0].title).toBe("First Form");
525
- (0, bun_test_1.expect)(res.body.data[1].title).toBe("Second Form");
526
- return [2 /*return*/];
527
- }
528
- });
529
- }); });
530
- (0, bun_test_1.it)("applies resolveConsentForms callback to filter forms", function () { return __awaiter(void 0, void 0, void 0, function () {
531
- var filteredApp, filteredAgent, res;
532
- return __generator(this, function (_a) {
533
- switch (_a.label) {
534
- case 0: return [4 /*yield*/, Promise.all([
535
- consentForm_1.ConsentForm.create({
536
- active: true,
537
- content: new Map([["en", "# Privacy"]]),
538
- order: 1,
539
- slug: "resolver-privacy",
540
- title: "Privacy",
541
- type: "privacy",
542
- version: 1,
543
- }),
544
- consentForm_1.ConsentForm.create({
545
- active: true,
546
- content: new Map([["en", "# Terms"]]),
547
- order: 2,
548
- slug: "resolver-terms",
549
- title: "Terms",
550
- type: "terms",
551
- version: 1,
552
- }),
553
- ])];
554
- case 1:
555
- _a.sent();
556
- filteredApp = buildApp({
557
- resolveConsentForms: function (_user, forms) { return forms.filter(function (f) { return f.type === "privacy"; }); },
558
- });
559
- return [4 /*yield*/, (0, tests_1.authAsUser)(filteredApp, "notAdmin")];
560
- case 2:
561
- filteredAgent = _a.sent();
562
- return [4 /*yield*/, filteredAgent.get("/consents/pending").expect(200)];
563
- case 3:
564
- res = _a.sent();
565
- (0, bun_test_1.expect)(res.body.data).toHaveLength(1);
566
- (0, bun_test_1.expect)(res.body.data[0].type).toBe("privacy");
567
- return [2 /*return*/];
568
- }
569
- });
570
- }); });
571
- (0, bun_test_1.it)("resolveConsentForms can filter by user admin status", function () { return __awaiter(void 0, void 0, void 0, function () {
572
- var filteredApp, filteredAdmin, filteredUser, adminRes, userRes;
573
- return __generator(this, function (_a) {
574
- switch (_a.label) {
575
- case 0: return [4 /*yield*/, consentForm_1.ConsentForm.create({
576
- active: true,
577
- content: new Map([["en", "# Terms"]]),
578
- order: 1,
579
- slug: "admin-filter-terms",
580
- title: "Terms",
581
- type: "terms",
582
- version: 1,
583
- })];
584
- case 1:
585
- _a.sent();
586
- filteredApp = buildApp({
587
- resolveConsentForms: function (user, forms) { return (user.admin ? [] : forms); },
588
- });
589
- return [4 /*yield*/, (0, tests_1.authAsUser)(filteredApp, "admin")];
590
- case 2:
591
- filteredAdmin = _a.sent();
592
- return [4 /*yield*/, (0, tests_1.authAsUser)(filteredApp, "notAdmin")];
593
- case 3:
594
- filteredUser = _a.sent();
595
- return [4 /*yield*/, filteredAdmin.get("/consents/pending").expect(200)];
596
- case 4:
597
- adminRes = _a.sent();
598
- (0, bun_test_1.expect)(adminRes.body.data).toHaveLength(0);
599
- return [4 /*yield*/, filteredUser.get("/consents/pending").expect(200)];
600
- case 5:
601
- userRes = _a.sent();
602
- (0, bun_test_1.expect)(userRes.body.data).toHaveLength(1);
603
- return [2 /*return*/];
604
- }
605
- });
606
- }); });
607
- (0, bun_test_1.it)("requires authentication", function () { return __awaiter(void 0, void 0, void 0, function () {
608
- var app;
609
- return __generator(this, function (_a) {
610
- switch (_a.label) {
611
- case 0:
612
- app = buildApp();
613
- return [4 /*yield*/, (0, supertest_1.default)(app).get("/consents/pending").expect(401)];
614
- case 1:
615
- _a.sent();
616
- return [2 /*return*/];
617
- }
618
- });
619
- }); });
620
- });
621
- (0, bun_test_1.describe)("POST /consents/respond", function () {
622
- var form;
623
- (0, bun_test_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
624
- return __generator(this, function (_a) {
625
- switch (_a.label) {
626
- case 0: return [4 /*yield*/, consentForm_1.ConsentForm.create({
627
- active: true,
628
- content: new Map([["en", "# Terms"]]),
629
- order: 1,
630
- slug: "respond-terms",
631
- title: "Terms",
632
- type: "terms",
633
- version: 1,
634
- })];
635
- case 1:
636
- form = _a.sent();
637
- return [2 /*return*/];
638
- }
639
- });
640
- }); });
641
- (0, bun_test_1.it)("creates a consent response", function () { return __awaiter(void 0, void 0, void 0, function () {
642
- var res;
643
- return __generator(this, function (_a) {
644
- switch (_a.label) {
645
- case 0: return [4 /*yield*/, userAgent
646
- .post("/consents/respond")
647
- .send({
648
- agreed: true,
649
- consentFormId: form._id,
650
- locale: "en",
651
- })
652
- .expect(200)];
653
- case 1:
654
- res = _a.sent();
655
- (0, bun_test_1.expect)(res.body.data.agreed).toBe(true);
656
- (0, bun_test_1.expect)(res.body.data.locale).toBe("en");
657
- return [2 /*return*/];
658
- }
659
- });
660
- }); });
661
- (0, bun_test_1.it)("returns 400 when consentFormId is missing", function () { return __awaiter(void 0, void 0, void 0, function () {
662
- return __generator(this, function (_a) {
663
- switch (_a.label) {
664
- case 0: return [4 /*yield*/, userAgent.post("/consents/respond").send({ agreed: true, locale: "en" }).expect(400)];
665
- case 1:
666
- _a.sent();
667
- return [2 /*return*/];
668
- }
669
- });
670
- }); });
671
- (0, bun_test_1.it)("returns 400 when agreed field is missing", function () { return __awaiter(void 0, void 0, void 0, function () {
672
- return __generator(this, function (_a) {
673
- switch (_a.label) {
674
- case 0: return [4 /*yield*/, userAgent
675
- .post("/consents/respond")
676
- .send({ consentFormId: form._id, locale: "en" })
677
- .expect(400)];
678
- case 1:
679
- _a.sent();
680
- return [2 /*return*/];
681
- }
682
- });
683
- }); });
684
- (0, bun_test_1.it)("returns 400 when locale is missing", function () { return __awaiter(void 0, void 0, void 0, function () {
685
- return __generator(this, function (_a) {
686
- switch (_a.label) {
687
- case 0: return [4 /*yield*/, userAgent
688
- .post("/consents/respond")
689
- .send({ agreed: true, consentFormId: form._id })
690
- .expect(400)];
691
- case 1:
692
- _a.sent();
693
- return [2 /*return*/];
694
- }
695
- });
696
- }); });
697
- (0, bun_test_1.it)("returns 400 when form is not active", function () { return __awaiter(void 0, void 0, void 0, function () {
698
- var inactiveForm;
699
- return __generator(this, function (_a) {
700
- switch (_a.label) {
701
- case 0: return [4 /*yield*/, consentForm_1.ConsentForm.create({
702
- active: false,
703
- content: new Map([["en", "# Inactive"]]),
704
- order: 5,
705
- slug: "inactive-form",
706
- title: "Inactive Form",
707
- type: "custom",
708
- version: 1,
709
- })];
710
- case 1:
711
- inactiveForm = _a.sent();
712
- return [4 /*yield*/, userAgent
713
- .post("/consents/respond")
714
- .send({ agreed: true, consentFormId: inactiveForm._id, locale: "en" })
715
- .expect(400)];
716
- case 2:
717
- _a.sent();
718
- return [2 /*return*/];
719
- }
720
- });
721
- }); });
722
- (0, bun_test_1.it)("validates required checkboxes when agreed is true", function () { return __awaiter(void 0, void 0, void 0, function () {
723
- var formWithRequired, res;
724
- return __generator(this, function (_a) {
725
- switch (_a.label) {
726
- case 0: return [4 /*yield*/, consentForm_1.ConsentForm.create({
727
- active: true,
728
- checkboxes: [{ label: "I confirm", required: true }],
729
- content: new Map([["en", "# Required Checkbox Form"]]),
730
- order: 6,
731
- slug: "required-checkbox-form",
732
- title: "Required Checkbox Form",
733
- type: "agreement",
734
- version: 1,
735
- })];
736
- case 1:
737
- formWithRequired = _a.sent();
738
- // Agree without checking the required checkbox
739
- return [4 /*yield*/, userAgent
740
- .post("/consents/respond")
741
- .send({
742
- agreed: true,
743
- checkboxValues: { "0": false },
744
- consentFormId: formWithRequired._id,
745
- locale: "en",
746
- })
747
- .expect(400)];
748
- case 2:
749
- // Agree without checking the required checkbox
750
- _a.sent();
751
- return [4 /*yield*/, userAgent
752
- .post("/consents/respond")
753
- .send({
754
- agreed: true,
755
- checkboxValues: { "0": true },
756
- consentFormId: formWithRequired._id,
757
- locale: "en",
758
- })
759
- .expect(200)];
760
- case 3:
761
- res = _a.sent();
762
- (0, bun_test_1.expect)(res.body.data.agreed).toBe(true);
763
- return [2 /*return*/];
764
- }
765
- });
766
- }); });
767
- (0, bun_test_1.it)("requires signature when captureSignature is true and agreed is true", function () { return __awaiter(void 0, void 0, void 0, function () {
768
- var sigForm, res;
769
- return __generator(this, function (_a) {
770
- switch (_a.label) {
771
- case 0: return [4 /*yield*/, consentForm_1.ConsentForm.create({
772
- active: true,
773
- captureSignature: true,
774
- content: new Map([["en", "# Signature Required"]]),
775
- order: 7,
776
- slug: "sig-form",
777
- title: "Signature Form",
778
- type: "agreement",
779
- version: 1,
780
- })];
781
- case 1:
782
- sigForm = _a.sent();
783
- return [4 /*yield*/, userAgent
784
- .post("/consents/respond")
785
- .send({ agreed: true, consentFormId: sigForm._id, locale: "en" })
786
- .expect(400)];
787
- case 2:
788
- _a.sent();
789
- return [4 /*yield*/, userAgent
790
- .post("/consents/respond")
791
- .send({
792
- agreed: true,
793
- consentFormId: sigForm._id,
794
- locale: "en",
795
- signature: "data:image/png;base64,abc123",
796
- })
797
- .expect(200)];
798
- case 3:
799
- res = _a.sent();
800
- (0, bun_test_1.expect)(res.body.data.signature).toBe("data:image/png;base64,abc123");
801
- return [2 /*return*/];
802
- }
803
- });
804
- }); });
805
- (0, bun_test_1.it)("stores formVersionSnapshot always", function () { return __awaiter(void 0, void 0, void 0, function () {
806
- var res;
807
- return __generator(this, function (_a) {
808
- switch (_a.label) {
809
- case 0: return [4 /*yield*/, userAgent
810
- .post("/consents/respond")
811
- .send({ agreed: true, consentFormId: form._id, locale: "en" })
812
- .expect(200)];
813
- case 1:
814
- res = _a.sent();
815
- (0, bun_test_1.expect)(res.body.data.formVersionSnapshot).toBe(1);
816
- return [2 /*return*/];
817
- }
818
- });
819
- }); });
820
- (0, bun_test_1.it)("stores audit trail fields when auditTrail is enabled", function () { return __awaiter(void 0, void 0, void 0, function () {
821
- var res;
822
- return __generator(this, function (_a) {
823
- switch (_a.label) {
824
- case 0: return [4 /*yield*/, userAgent
825
- .post("/consents/respond")
826
- .send({ agreed: true, consentFormId: form._id, locale: "en" })
827
- .expect(200)];
828
- case 1:
829
- res = _a.sent();
830
- (0, bun_test_1.expect)(res.body.data.contentSnapshot).toBeDefined();
831
- (0, bun_test_1.expect)(res.body.data.contentSnapshot).toContain("Terms");
832
- return [2 /*return*/];
833
- }
834
- });
835
- }); });
836
- (0, bun_test_1.it)("requires authentication", function () { return __awaiter(void 0, void 0, void 0, function () {
837
- var app;
838
- return __generator(this, function (_a) {
839
- switch (_a.label) {
840
- case 0:
841
- app = buildApp();
842
- return [4 /*yield*/, (0, supertest_1.default)(app)
843
- .post("/consents/respond")
844
- .send({ agreed: true, consentFormId: form._id, locale: "en" })
845
- .expect(401)];
846
- case 1:
847
- _a.sent();
848
- return [2 /*return*/];
849
- }
850
- });
851
- }); });
852
- });
853
- (0, bun_test_1.describe)("GET /consents/my", function () {
854
- (0, bun_test_1.it)("returns empty array when user has no consents", function () { return __awaiter(void 0, void 0, void 0, function () {
855
- var res;
856
- return __generator(this, function (_a) {
857
- switch (_a.label) {
858
- case 0: return [4 /*yield*/, userAgent.get("/consents/my").expect(200)];
859
- case 1:
860
- res = _a.sent();
861
- (0, bun_test_1.expect)(res.body.data).toHaveLength(0);
862
- return [2 /*return*/];
863
- }
864
- });
865
- }); });
866
- (0, bun_test_1.it)("returns user consent history with populated form data", function () { return __awaiter(void 0, void 0, void 0, function () {
867
- var form, res, item;
868
- return __generator(this, function (_a) {
869
- switch (_a.label) {
870
- case 0: return [4 /*yield*/, consentForm_1.ConsentForm.create({
871
- active: true,
872
- checkboxes: [{ label: "I agree to the terms", required: true }],
873
- content: new Map([["en", "# Terms"]]),
874
- order: 1,
875
- slug: "my-terms",
876
- title: "Terms of Service",
877
- type: "terms",
878
- version: 2,
879
- })];
880
- case 1:
881
- form = _a.sent();
882
- return [4 /*yield*/, consentResponse_1.ConsentResponse.create({
883
- agreed: true,
884
- agreedAt: new Date(),
885
- checkboxValues: new Map([["0", true]]),
886
- consentFormId: form._id,
887
- formVersionSnapshot: 2,
888
- locale: "en",
889
- userId: notAdmin._id,
890
- })];
891
- case 2:
892
- _a.sent();
893
- return [4 /*yield*/, userAgent.get("/consents/my").expect(200)];
894
- case 3:
895
- res = _a.sent();
896
- (0, bun_test_1.expect)(res.body.data).toHaveLength(1);
897
- item = res.body.data[0];
898
- (0, bun_test_1.expect)(item.agreed).toBe(true);
899
- (0, bun_test_1.expect)(item.locale).toBe("en");
900
- (0, bun_test_1.expect)(item.formVersionSnapshot).toBe(2);
901
- (0, bun_test_1.expect)(item.form).toBeDefined();
902
- (0, bun_test_1.expect)(item.form.title).toBe("Terms of Service");
903
- (0, bun_test_1.expect)(item.form.slug).toBe("my-terms");
904
- (0, bun_test_1.expect)(item.form.type).toBe("terms");
905
- (0, bun_test_1.expect)(item.form.version).toBe(2);
906
- (0, bun_test_1.expect)(item.form.checkboxes).toHaveLength(1);
907
- (0, bun_test_1.expect)(item.form.checkboxes[0].label).toBe("I agree to the terms");
908
- return [2 /*return*/];
909
- }
910
- });
911
- }); });
912
- (0, bun_test_1.it)("returns responses sorted by agreedAt descending", function () { return __awaiter(void 0, void 0, void 0, function () {
913
- var form, olderDate, newerDate, res;
914
- return __generator(this, function (_a) {
915
- switch (_a.label) {
916
- case 0: return [4 /*yield*/, consentForm_1.ConsentForm.create({
917
- active: true,
918
- content: new Map([["en", "# Terms"]]),
919
- order: 1,
920
- slug: "sorted-terms",
921
- title: "Terms",
922
- type: "terms",
923
- version: 1,
924
- })];
925
- case 1:
926
- form = _a.sent();
927
- olderDate = new Date("2025-01-01T00:00:00Z");
928
- newerDate = new Date("2025-06-01T00:00:00Z");
929
- return [4 /*yield*/, consentResponse_1.ConsentResponse.create({
930
- agreed: true,
931
- agreedAt: olderDate,
932
- consentFormId: form._id,
933
- formVersionSnapshot: 1,
934
- locale: "en",
935
- userId: notAdmin._id,
936
- })];
937
- case 2:
938
- _a.sent();
939
- return [4 /*yield*/, consentResponse_1.ConsentResponse.create({
940
- agreed: false,
941
- agreedAt: newerDate,
942
- consentFormId: form._id,
943
- formVersionSnapshot: 1,
944
- locale: "en",
945
- userId: notAdmin._id,
946
- })];
947
- case 3:
948
- _a.sent();
949
- return [4 /*yield*/, userAgent.get("/consents/my").expect(200)];
950
- case 4:
951
- res = _a.sent();
952
- (0, bun_test_1.expect)(res.body.data).toHaveLength(2);
953
- (0, bun_test_1.expect)(res.body.data[0].agreed).toBe(false); // newer first
954
- (0, bun_test_1.expect)(res.body.data[1].agreed).toBe(true); // older second
955
- return [2 /*return*/];
956
- }
957
- });
958
- }); });
959
- (0, bun_test_1.it)("includes audit trail fields when present", function () { return __awaiter(void 0, void 0, void 0, function () {
960
- var form, res, item;
961
- return __generator(this, function (_a) {
962
- switch (_a.label) {
963
- case 0: return [4 /*yield*/, consentForm_1.ConsentForm.create({
964
- active: true,
965
- content: new Map([["en", "# Audit Terms"]]),
966
- order: 1,
967
- slug: "audit-my-terms",
968
- title: "Audit Terms",
969
- type: "terms",
970
- version: 1,
971
- })];
972
- case 1:
973
- form = _a.sent();
974
- return [4 /*yield*/, consentResponse_1.ConsentResponse.create({
975
- agreed: true,
976
- agreedAt: new Date(),
977
- consentFormId: form._id,
978
- contentSnapshot: "# Audit Terms",
979
- formVersionSnapshot: 1,
980
- ipAddress: "192.168.1.1",
981
- locale: "en",
982
- userAgent: "Mozilla/5.0 Test Agent",
983
- userId: notAdmin._id,
984
- })];
985
- case 2:
986
- _a.sent();
987
- return [4 /*yield*/, userAgent.get("/consents/my").expect(200)];
988
- case 3:
989
- res = _a.sent();
990
- (0, bun_test_1.expect)(res.body.data).toHaveLength(1);
991
- item = res.body.data[0];
992
- (0, bun_test_1.expect)(item.ipAddress).toBe("192.168.1.1");
993
- (0, bun_test_1.expect)(item.userAgent).toBe("Mozilla/5.0 Test Agent");
994
- (0, bun_test_1.expect)(item.contentSnapshot).toBe("# Audit Terms");
995
- return [2 /*return*/];
996
- }
997
- });
998
- }); });
999
- (0, bun_test_1.it)("includes signature when present", function () { return __awaiter(void 0, void 0, void 0, function () {
1000
- var form, signedAt, res, item;
1001
- return __generator(this, function (_a) {
1002
- switch (_a.label) {
1003
- case 0: return [4 /*yield*/, consentForm_1.ConsentForm.create({
1004
- active: true,
1005
- captureSignature: true,
1006
- content: new Map([["en", "# Signature Terms"]]),
1007
- order: 1,
1008
- slug: "sig-my-terms",
1009
- title: "Signature Terms",
1010
- type: "agreement",
1011
- version: 1,
1012
- })];
1013
- case 1:
1014
- form = _a.sent();
1015
- signedAt = new Date();
1016
- return [4 /*yield*/, consentResponse_1.ConsentResponse.create({
1017
- agreed: true,
1018
- agreedAt: new Date(),
1019
- consentFormId: form._id,
1020
- formVersionSnapshot: 1,
1021
- locale: "en",
1022
- signature: "data:image/png;base64,sig123",
1023
- signedAt: signedAt,
1024
- userId: notAdmin._id,
1025
- })];
1026
- case 2:
1027
- _a.sent();
1028
- return [4 /*yield*/, userAgent.get("/consents/my").expect(200)];
1029
- case 3:
1030
- res = _a.sent();
1031
- (0, bun_test_1.expect)(res.body.data).toHaveLength(1);
1032
- item = res.body.data[0];
1033
- (0, bun_test_1.expect)(item.signature).toBe("data:image/png;base64,sig123");
1034
- (0, bun_test_1.expect)(item.signedAt).toBeDefined();
1035
- return [2 /*return*/];
1036
- }
1037
- });
1038
- }); });
1039
- (0, bun_test_1.it)("does not return other users' consents", function () { return __awaiter(void 0, void 0, void 0, function () {
1040
- var form, adminRes, userRes;
1041
- return __generator(this, function (_a) {
1042
- switch (_a.label) {
1043
- case 0: return [4 /*yield*/, consentForm_1.ConsentForm.create({
1044
- active: true,
1045
- content: new Map([["en", "# Isolation Terms"]]),
1046
- order: 1,
1047
- slug: "isolation-terms",
1048
- title: "Isolation Terms",
1049
- type: "terms",
1050
- version: 1,
1051
- })];
1052
- case 1:
1053
- form = _a.sent();
1054
- return [4 /*yield*/, consentResponse_1.ConsentResponse.create({
1055
- agreed: true,
1056
- agreedAt: new Date(),
1057
- consentFormId: form._id,
1058
- formVersionSnapshot: 1,
1059
- locale: "en",
1060
- userId: admin._id,
1061
- })];
1062
- case 2:
1063
- _a.sent();
1064
- return [4 /*yield*/, consentResponse_1.ConsentResponse.create({
1065
- agreed: true,
1066
- agreedAt: new Date(),
1067
- consentFormId: form._id,
1068
- formVersionSnapshot: 1,
1069
- locale: "en",
1070
- userId: notAdmin._id,
1071
- })];
1072
- case 3:
1073
- _a.sent();
1074
- return [4 /*yield*/, adminAgent.get("/consents/my").expect(200)];
1075
- case 4:
1076
- adminRes = _a.sent();
1077
- (0, bun_test_1.expect)(adminRes.body.data).toHaveLength(1);
1078
- (0, bun_test_1.expect)(adminRes.body.data[0].form.title).toBe("Isolation Terms");
1079
- return [4 /*yield*/, userAgent.get("/consents/my").expect(200)];
1080
- case 5:
1081
- userRes = _a.sent();
1082
- (0, bun_test_1.expect)(userRes.body.data).toHaveLength(1);
1083
- (0, bun_test_1.expect)(userRes.body.data[0].form.title).toBe("Isolation Terms");
1084
- return [2 /*return*/];
1085
- }
1086
- });
1087
- }); });
1088
- (0, bun_test_1.it)("requires authentication", function () { return __awaiter(void 0, void 0, void 0, function () {
1089
- var app;
1090
- return __generator(this, function (_a) {
1091
- switch (_a.label) {
1092
- case 0:
1093
- app = buildApp();
1094
- return [4 /*yield*/, (0, supertest_1.default)(app).get("/consents/my").expect(401)];
1095
- case 1:
1096
- _a.sent();
1097
- return [2 /*return*/];
1098
- }
1099
- });
1100
- }); });
1101
- });
1102
- (0, bun_test_1.describe)("POST /consent-forms/generate (aiConfig)", function () {
1103
- var aiConfig = {
1104
- generateContent: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
1105
- var type = _b.type, description = _b.description, locale = _b.locale;
1106
- return __generator(this, function (_c) {
1107
- return [2 /*return*/, "Generated ".concat(type, " content (").concat(locale, ") for: ").concat(description)];
1108
- });
1109
- }); },
1110
- translateContent: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
1111
- var content = _b.content, fromLocale = _b.fromLocale, toLocale = _b.toLocale;
1112
- return __generator(this, function (_c) {
1113
- return [2 /*return*/, "[".concat(fromLocale, "->").concat(toLocale, "] ").concat(content)];
1114
- });
1115
- }); },
1116
- };
1117
- (0, bun_test_1.it)("generates consent form content for admins", function () { return __awaiter(void 0, void 0, void 0, function () {
1118
- var aiApp, aiAdmin, res;
1119
- return __generator(this, function (_a) {
1120
- switch (_a.label) {
1121
- case 0:
1122
- aiApp = buildApp({ aiConfig: aiConfig });
1123
- return [4 /*yield*/, (0, tests_1.authAsUser)(aiApp, "admin")];
1124
- case 1:
1125
- aiAdmin = _a.sent();
1126
- return [4 /*yield*/, aiAdmin
1127
- .post("/consent-forms/generate")
1128
- .send({ description: "Privacy policy for a health app", locale: "es", type: "privacy" })
1129
- .expect(200)];
1130
- case 2:
1131
- res = _a.sent();
1132
- (0, bun_test_1.expect)(res.body.data.content).toBe("Generated privacy content (es) for: Privacy policy for a health app");
1133
- return [2 /*return*/];
1134
- }
1135
- });
1136
- }); });
1137
- (0, bun_test_1.it)("defaults locale to en when not provided", function () { return __awaiter(void 0, void 0, void 0, function () {
1138
- var aiApp, aiAdmin, res;
1139
- return __generator(this, function (_a) {
1140
- switch (_a.label) {
1141
- case 0:
1142
- aiApp = buildApp({ aiConfig: aiConfig });
1143
- return [4 /*yield*/, (0, tests_1.authAsUser)(aiApp, "admin")];
1144
- case 1:
1145
- aiAdmin = _a.sent();
1146
- return [4 /*yield*/, aiAdmin
1147
- .post("/consent-forms/generate")
1148
- .send({ description: "Terms", type: "terms" })
1149
- .expect(200)];
1150
- case 2:
1151
- res = _a.sent();
1152
- (0, bun_test_1.expect)(res.body.data.content).toContain("(en)");
1153
- return [2 /*return*/];
1154
- }
1155
- });
1156
- }); });
1157
- (0, bun_test_1.it)("returns 403 for non-admin users", function () { return __awaiter(void 0, void 0, void 0, function () {
1158
- var aiApp, aiUser;
1159
- return __generator(this, function (_a) {
1160
- switch (_a.label) {
1161
- case 0:
1162
- aiApp = buildApp({ aiConfig: aiConfig });
1163
- return [4 /*yield*/, (0, tests_1.authAsUser)(aiApp, "notAdmin")];
1164
- case 1:
1165
- aiUser = _a.sent();
1166
- return [4 /*yield*/, aiUser
1167
- .post("/consent-forms/generate")
1168
- .send({ description: "Privacy", type: "privacy" })
1169
- .expect(403)];
1170
- case 2:
1171
- _a.sent();
1172
- return [2 /*return*/];
1173
- }
1174
- });
1175
- }); });
1176
- (0, bun_test_1.it)("returns 400 when type is missing", function () { return __awaiter(void 0, void 0, void 0, function () {
1177
- var aiApp, aiAdmin;
1178
- return __generator(this, function (_a) {
1179
- switch (_a.label) {
1180
- case 0:
1181
- aiApp = buildApp({ aiConfig: aiConfig });
1182
- return [4 /*yield*/, (0, tests_1.authAsUser)(aiApp, "admin")];
1183
- case 1:
1184
- aiAdmin = _a.sent();
1185
- return [4 /*yield*/, aiAdmin.post("/consent-forms/generate").send({ description: "Privacy" }).expect(400)];
1186
- case 2:
1187
- _a.sent();
1188
- return [2 /*return*/];
1189
- }
1190
- });
1191
- }); });
1192
- (0, bun_test_1.it)("returns 400 when description is missing", function () { return __awaiter(void 0, void 0, void 0, function () {
1193
- var aiApp, aiAdmin;
1194
- return __generator(this, function (_a) {
1195
- switch (_a.label) {
1196
- case 0:
1197
- aiApp = buildApp({ aiConfig: aiConfig });
1198
- return [4 /*yield*/, (0, tests_1.authAsUser)(aiApp, "admin")];
1199
- case 1:
1200
- aiAdmin = _a.sent();
1201
- return [4 /*yield*/, aiAdmin.post("/consent-forms/generate").send({ type: "privacy" }).expect(400)];
1202
- case 2:
1203
- _a.sent();
1204
- return [2 /*return*/];
1205
- }
1206
- });
1207
- }); });
1208
- (0, bun_test_1.it)("returns 404 when aiConfig is not provided", function () { return __awaiter(void 0, void 0, void 0, function () {
1209
- return __generator(this, function (_a) {
1210
- switch (_a.label) {
1211
- case 0: return [4 /*yield*/, adminAgent
1212
- .post("/consent-forms/generate")
1213
- .send({ description: "Privacy", type: "privacy" })
1214
- .expect(404)];
1215
- case 1:
1216
- _a.sent();
1217
- return [2 /*return*/];
1218
- }
1219
- });
1220
- }); });
1221
- });
1222
- (0, bun_test_1.describe)("POST /consent-forms/translate (aiConfig)", function () {
1223
- var aiConfig = {
1224
- generateContent: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
1225
- var type = _b.type, description = _b.description, locale = _b.locale;
1226
- return __generator(this, function (_c) {
1227
- return [2 /*return*/, "Generated ".concat(type, " content (").concat(locale, ") for: ").concat(description)];
1228
- });
1229
- }); },
1230
- translateContent: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
1231
- var content = _b.content, fromLocale = _b.fromLocale, toLocale = _b.toLocale;
1232
- return __generator(this, function (_c) {
1233
- return [2 /*return*/, "[".concat(fromLocale, "->").concat(toLocale, "] ").concat(content)];
1234
- });
1235
- }); },
1236
- };
1237
- (0, bun_test_1.it)("translates consent form content for admins", function () { return __awaiter(void 0, void 0, void 0, function () {
1238
- var aiApp, aiAdmin, res;
1239
- return __generator(this, function (_a) {
1240
- switch (_a.label) {
1241
- case 0:
1242
- aiApp = buildApp({ aiConfig: aiConfig });
1243
- return [4 /*yield*/, (0, tests_1.authAsUser)(aiApp, "admin")];
1244
- case 1:
1245
- aiAdmin = _a.sent();
1246
- return [4 /*yield*/, aiAdmin
1247
- .post("/consent-forms/translate")
1248
- .send({ content: "Hello world", fromLocale: "en", toLocale: "es" })
1249
- .expect(200)];
1250
- case 2:
1251
- res = _a.sent();
1252
- (0, bun_test_1.expect)(res.body.data.content).toBe("[en->es] Hello world");
1253
- return [2 /*return*/];
1254
- }
1255
- });
1256
- }); });
1257
- (0, bun_test_1.it)("returns 403 for non-admin users", function () { return __awaiter(void 0, void 0, void 0, function () {
1258
- var aiApp, aiUser;
1259
- return __generator(this, function (_a) {
1260
- switch (_a.label) {
1261
- case 0:
1262
- aiApp = buildApp({ aiConfig: aiConfig });
1263
- return [4 /*yield*/, (0, tests_1.authAsUser)(aiApp, "notAdmin")];
1264
- case 1:
1265
- aiUser = _a.sent();
1266
- return [4 /*yield*/, aiUser
1267
- .post("/consent-forms/translate")
1268
- .send({ content: "Hello", fromLocale: "en", toLocale: "es" })
1269
- .expect(403)];
1270
- case 2:
1271
- _a.sent();
1272
- return [2 /*return*/];
1273
- }
1274
- });
1275
- }); });
1276
- (0, bun_test_1.it)("returns 400 when content is missing", function () { return __awaiter(void 0, void 0, void 0, function () {
1277
- var aiApp, aiAdmin;
1278
- return __generator(this, function (_a) {
1279
- switch (_a.label) {
1280
- case 0:
1281
- aiApp = buildApp({ aiConfig: aiConfig });
1282
- return [4 /*yield*/, (0, tests_1.authAsUser)(aiApp, "admin")];
1283
- case 1:
1284
- aiAdmin = _a.sent();
1285
- return [4 /*yield*/, aiAdmin
1286
- .post("/consent-forms/translate")
1287
- .send({ fromLocale: "en", toLocale: "es" })
1288
- .expect(400)];
1289
- case 2:
1290
- _a.sent();
1291
- return [2 /*return*/];
1292
- }
1293
- });
1294
- }); });
1295
- (0, bun_test_1.it)("returns 400 when fromLocale is missing", function () { return __awaiter(void 0, void 0, void 0, function () {
1296
- var aiApp, aiAdmin;
1297
- return __generator(this, function (_a) {
1298
- switch (_a.label) {
1299
- case 0:
1300
- aiApp = buildApp({ aiConfig: aiConfig });
1301
- return [4 /*yield*/, (0, tests_1.authAsUser)(aiApp, "admin")];
1302
- case 1:
1303
- aiAdmin = _a.sent();
1304
- return [4 /*yield*/, aiAdmin
1305
- .post("/consent-forms/translate")
1306
- .send({ content: "Hello", toLocale: "es" })
1307
- .expect(400)];
1308
- case 2:
1309
- _a.sent();
1310
- return [2 /*return*/];
1311
- }
1312
- });
1313
- }); });
1314
- (0, bun_test_1.it)("returns 400 when toLocale is missing", function () { return __awaiter(void 0, void 0, void 0, function () {
1315
- var aiApp, aiAdmin;
1316
- return __generator(this, function (_a) {
1317
- switch (_a.label) {
1318
- case 0:
1319
- aiApp = buildApp({ aiConfig: aiConfig });
1320
- return [4 /*yield*/, (0, tests_1.authAsUser)(aiApp, "admin")];
1321
- case 1:
1322
- aiAdmin = _a.sent();
1323
- return [4 /*yield*/, aiAdmin
1324
- .post("/consent-forms/translate")
1325
- .send({ content: "Hello", fromLocale: "en" })
1326
- .expect(400)];
1327
- case 2:
1328
- _a.sent();
1329
- return [2 /*return*/];
1330
- }
1331
- });
1332
- }); });
1333
- (0, bun_test_1.it)("returns 404 when aiConfig is not provided", function () { return __awaiter(void 0, void 0, void 0, function () {
1334
- return __generator(this, function (_a) {
1335
- switch (_a.label) {
1336
- case 0: return [4 /*yield*/, adminAgent
1337
- .post("/consent-forms/translate")
1338
- .send({ content: "Hello", fromLocale: "en", toLocale: "es" })
1339
- .expect(404)];
1340
- case 1:
1341
- _a.sent();
1342
- return [2 /*return*/];
1343
- }
1344
- });
1345
- }); });
1346
- });
1347
- (0, bun_test_1.describe)("GET /consents/audit/:userId", function () {
1348
- (0, bun_test_1.it)("returns audit history for a user when auditTrail is enabled", function () { return __awaiter(void 0, void 0, void 0, function () {
1349
- var form, res;
1350
- return __generator(this, function (_a) {
1351
- switch (_a.label) {
1352
- case 0: return [4 /*yield*/, consentForm_1.ConsentForm.create({
1353
- active: true,
1354
- content: new Map([["en", "# Audit Terms"]]),
1355
- order: 1,
1356
- slug: "audit-terms",
1357
- title: "Audit Terms",
1358
- type: "terms",
1359
- version: 1,
1360
- })];
1361
- case 1:
1362
- form = _a.sent();
1363
- return [4 /*yield*/, consentResponse_1.ConsentResponse.create({
1364
- agreed: true,
1365
- agreedAt: new Date(),
1366
- consentFormId: form._id,
1367
- contentSnapshot: "# Audit Terms",
1368
- formVersionSnapshot: 1,
1369
- locale: "en",
1370
- userId: notAdmin._id,
1371
- })];
1372
- case 2:
1373
- _a.sent();
1374
- return [4 /*yield*/, adminAgent.get("/consents/audit/".concat(notAdmin._id)).expect(200)];
1375
- case 3:
1376
- res = _a.sent();
1377
- (0, bun_test_1.expect)(res.body.data).toHaveLength(1);
1378
- (0, bun_test_1.expect)(res.body.data[0].agreed).toBe(true);
1379
- (0, bun_test_1.expect)(res.body.data[0].form.title).toBe("Audit Terms");
1380
- return [2 /*return*/];
1381
- }
1382
- });
1383
- }); });
1384
- (0, bun_test_1.it)("returns 403 for non-admin users", function () { return __awaiter(void 0, void 0, void 0, function () {
1385
- return __generator(this, function (_a) {
1386
- switch (_a.label) {
1387
- case 0: return [4 /*yield*/, userAgent.get("/consents/audit/".concat(notAdmin._id)).expect(403)];
1388
- case 1:
1389
- _a.sent();
1390
- return [2 /*return*/];
1391
- }
1392
- });
1393
- }); });
1394
- (0, bun_test_1.it)("returns 404 when auditTrail is disabled", function () { return __awaiter(void 0, void 0, void 0, function () {
1395
- var noAuditApp, noAuditAdmin;
1396
- return __generator(this, function (_a) {
1397
- switch (_a.label) {
1398
- case 0:
1399
- noAuditApp = buildApp({ auditTrail: false });
1400
- return [4 /*yield*/, (0, tests_1.authAsUser)(noAuditApp, "admin")];
1401
- case 1:
1402
- noAuditAdmin = _a.sent();
1403
- return [4 /*yield*/, noAuditAdmin.get("/consents/audit/".concat(notAdmin._id)).expect(404)];
1404
- case 2:
1405
- _a.sent();
1406
- return [2 /*return*/];
1407
- }
1408
- });
1409
- }); });
1410
- });
1411
- });