@terreno/api 0.22.2 → 0.23.1
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/api.test.js +6 -2
- package/dist/auth.test.js +52 -0
- package/dist/consentApp.d.ts +3 -0
- package/dist/consentApp.js +13 -7
- package/dist/consentApp.test.js +35 -0
- package/dist/envConfigurationPlugin.test.js +4 -6
- package/dist/notifiers/zoomNotifier.test.js +3 -2
- package/dist/scriptRunner.d.ts +77 -0
- package/dist/scriptRunner.js +258 -1
- package/dist/scriptRunner.test.d.ts +1 -0
- package/dist/scriptRunner.test.js +386 -0
- package/package.json +11 -11
- package/src/api.test.ts +5 -1
- package/src/auth.test.ts +38 -0
- package/src/consentApp.test.ts +26 -0
- package/src/consentApp.ts +14 -6
- package/src/envConfigurationPlugin.test.ts +4 -6
- package/src/notifiers/zoomNotifier.test.ts +7 -4
- package/src/scriptRunner.test.ts +284 -0
- package/src/scriptRunner.ts +249 -0
|
@@ -0,0 +1,386 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
var bun_test_1 = require("bun:test");
|
|
43
|
+
var mongoose_1 = __importDefault(require("mongoose"));
|
|
44
|
+
var scriptRunner_1 = require("./scriptRunner");
|
|
45
|
+
(0, bun_test_1.describe)("parseScriptArgs", function () {
|
|
46
|
+
(0, bun_test_1.it)("parses --name=value form", function () {
|
|
47
|
+
var args = (0, scriptRunner_1.parseScriptArgs)(["--model=todos"]).args;
|
|
48
|
+
(0, bun_test_1.expect)(args.getString("model")).toBe("todos");
|
|
49
|
+
(0, bun_test_1.expect)(args.has("model")).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
(0, bun_test_1.it)("parses --name value form", function () {
|
|
52
|
+
var args = (0, scriptRunner_1.parseScriptArgs)(["--model", "todos"]).args;
|
|
53
|
+
(0, bun_test_1.expect)(args.getString("model")).toBe("todos");
|
|
54
|
+
});
|
|
55
|
+
(0, bun_test_1.it)("treats a lone --flag as boolean true", function () {
|
|
56
|
+
var args = (0, scriptRunner_1.parseScriptArgs)(["--wet"]).args;
|
|
57
|
+
(0, bun_test_1.expect)(args.getBoolean("wet")).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
(0, bun_test_1.it)("parses --no-flag as boolean false", function () {
|
|
60
|
+
var args = (0, scriptRunner_1.parseScriptArgs)(["--no-cache"]).args;
|
|
61
|
+
(0, bun_test_1.expect)(args.getBoolean("cache")).toBe(false);
|
|
62
|
+
});
|
|
63
|
+
(0, bun_test_1.it)("treats short -x like --x", function () {
|
|
64
|
+
var args = (0, scriptRunner_1.parseScriptArgs)(["-v"]).args;
|
|
65
|
+
(0, bun_test_1.expect)(args.getBoolean("v")).toBe(true);
|
|
66
|
+
});
|
|
67
|
+
(0, bun_test_1.it)("collects positional arguments", function () {
|
|
68
|
+
var args = (0, scriptRunner_1.parseScriptArgs)(["one", "two", "-"]).args;
|
|
69
|
+
(0, bun_test_1.expect)(args.positional).toEqual(["one", "two", "-"]);
|
|
70
|
+
});
|
|
71
|
+
(0, bun_test_1.it)("collapses repeated flags into an array", function () {
|
|
72
|
+
var args = (0, scriptRunner_1.parseScriptArgs)(["--tag", "a", "--tag", "b", "--tag=c"]).args;
|
|
73
|
+
(0, bun_test_1.expect)(args.getStringArray("tag")).toEqual(["a", "b", "c"]);
|
|
74
|
+
});
|
|
75
|
+
(0, bun_test_1.it)("does not consume the next token for declared boolean flags", function () {
|
|
76
|
+
var defs = [{ description: "verbose", name: "verbose", type: "boolean" }];
|
|
77
|
+
var args = (0, scriptRunner_1.parseScriptArgs)(["--verbose", "leftover"], defs).args;
|
|
78
|
+
(0, bun_test_1.expect)(args.getBoolean("verbose")).toBe(true);
|
|
79
|
+
(0, bun_test_1.expect)(args.positional).toEqual(["leftover"]);
|
|
80
|
+
});
|
|
81
|
+
(0, bun_test_1.it)("resolves aliases to the canonical name", function () {
|
|
82
|
+
var defs = [
|
|
83
|
+
{ aliases: ["m"], description: "model", name: "model", type: "string" },
|
|
84
|
+
];
|
|
85
|
+
var args = (0, scriptRunner_1.parseScriptArgs)(["-m", "users"], defs).args;
|
|
86
|
+
(0, bun_test_1.expect)(args.getString("model")).toBe("users");
|
|
87
|
+
});
|
|
88
|
+
(0, bun_test_1.it)("treats a trailing flag with no value as boolean true", function () {
|
|
89
|
+
var args = (0, scriptRunner_1.parseScriptArgs)(["--model", "todos", "--wet"]).args;
|
|
90
|
+
(0, bun_test_1.expect)(args.getString("model")).toBe("todos");
|
|
91
|
+
(0, bun_test_1.expect)(args.getBoolean("wet")).toBe(true);
|
|
92
|
+
});
|
|
93
|
+
(0, bun_test_1.it)("errors when a declared string flag is missing its value", function () {
|
|
94
|
+
var defs = [{ description: "model", name: "model", type: "string" }];
|
|
95
|
+
var errors = (0, scriptRunner_1.parseScriptArgs)(["--model"], defs).errors;
|
|
96
|
+
(0, bun_test_1.expect)(errors).toHaveLength(1);
|
|
97
|
+
(0, bun_test_1.expect)(errors[0]).toInclude("--model expects a string value");
|
|
98
|
+
});
|
|
99
|
+
(0, bun_test_1.it)("errors when a declared number flag is followed by another flag", function () {
|
|
100
|
+
var defs = [{ description: "limit", name: "limit", type: "number" }];
|
|
101
|
+
var errors = (0, scriptRunner_1.parseScriptArgs)(["--limit", "--wet"], defs).errors;
|
|
102
|
+
(0, bun_test_1.expect)(errors.some(function (e) { return e.includes("--limit expects a number value"); })).toBe(true);
|
|
103
|
+
});
|
|
104
|
+
(0, bun_test_1.it)("still treats an undeclared value-less flag as boolean true", function () {
|
|
105
|
+
var _a = (0, scriptRunner_1.parseScriptArgs)(["--unknown"]), args = _a.args, errors = _a.errors;
|
|
106
|
+
(0, bun_test_1.expect)(errors).toHaveLength(0);
|
|
107
|
+
(0, bun_test_1.expect)(args.getBoolean("unknown")).toBe(true);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
(0, bun_test_1.describe)("createScriptArgs", function () {
|
|
111
|
+
(0, bun_test_1.it)("applies declared defaults when missing", function () {
|
|
112
|
+
var defs = [{ default: "all", description: "model", name: "model" }];
|
|
113
|
+
var _a = (0, scriptRunner_1.createScriptArgs)({ defs: defs, values: {} }), args = _a.args, errors = _a.errors;
|
|
114
|
+
(0, bun_test_1.expect)(errors).toHaveLength(0);
|
|
115
|
+
(0, bun_test_1.expect)(args.getString("model")).toBe("all");
|
|
116
|
+
});
|
|
117
|
+
(0, bun_test_1.it)("reports an error for missing required args", function () {
|
|
118
|
+
var defs = [{ description: "model", name: "model", required: true }];
|
|
119
|
+
var errors = (0, scriptRunner_1.createScriptArgs)({ defs: defs, values: {} }).errors;
|
|
120
|
+
(0, bun_test_1.expect)(errors).toHaveLength(1);
|
|
121
|
+
(0, bun_test_1.expect)(errors[0]).toInclude("Missing required argument: --model");
|
|
122
|
+
});
|
|
123
|
+
(0, bun_test_1.it)("coerces declared number args and reports invalid numbers", function () {
|
|
124
|
+
var defs = [{ description: "limit", name: "limit", type: "number" }];
|
|
125
|
+
var ok = (0, scriptRunner_1.createScriptArgs)({ defs: defs, values: { limit: "10" } });
|
|
126
|
+
(0, bun_test_1.expect)(ok.errors).toHaveLength(0);
|
|
127
|
+
(0, bun_test_1.expect)(ok.args.getNumber("limit")).toBe(10);
|
|
128
|
+
var bad = (0, scriptRunner_1.createScriptArgs)({ defs: defs, values: { limit: "nope" } });
|
|
129
|
+
(0, bun_test_1.expect)(bad.errors).toHaveLength(1);
|
|
130
|
+
(0, bun_test_1.expect)(bad.errors[0]).toInclude("expected a number");
|
|
131
|
+
});
|
|
132
|
+
(0, bun_test_1.it)("coerces declared boolean args", function () {
|
|
133
|
+
var defs = [{ description: "force", name: "force", type: "boolean" }];
|
|
134
|
+
(0, bun_test_1.expect)((0, scriptRunner_1.createScriptArgs)({ defs: defs, values: { force: "yes" } }).args.getBoolean("force")).toBe(true);
|
|
135
|
+
(0, bun_test_1.expect)((0, scriptRunner_1.createScriptArgs)({ defs: defs, values: { force: "off" } }).args.getBoolean("force")).toBe(false);
|
|
136
|
+
var bad = (0, scriptRunner_1.createScriptArgs)({ defs: defs, values: { force: "maybe" } });
|
|
137
|
+
(0, bun_test_1.expect)(bad.errors[0]).toInclude("expected a boolean");
|
|
138
|
+
});
|
|
139
|
+
(0, bun_test_1.it)("coerces booleans and numbers from array values (first element)", function () {
|
|
140
|
+
var defs = [
|
|
141
|
+
{ description: "force", name: "force", type: "boolean" },
|
|
142
|
+
{ description: "limit", name: "limit", type: "number" },
|
|
143
|
+
];
|
|
144
|
+
var args = (0, scriptRunner_1.createScriptArgs)({
|
|
145
|
+
defs: defs,
|
|
146
|
+
values: { force: ["true", "false"], limit: ["5", "6"] },
|
|
147
|
+
}).args;
|
|
148
|
+
(0, bun_test_1.expect)(args.getBoolean("force")).toBe(true);
|
|
149
|
+
(0, bun_test_1.expect)(args.getNumber("limit")).toBe(5);
|
|
150
|
+
});
|
|
151
|
+
(0, bun_test_1.describe)("getters", function () {
|
|
152
|
+
(0, bun_test_1.it)("getString returns fallback when missing and stringifies non-strings", function () {
|
|
153
|
+
var args = (0, scriptRunner_1.createScriptArgs)({ values: { count: 3, flag: true } }).args;
|
|
154
|
+
(0, bun_test_1.expect)(args.getString("missing", "fallback")).toBe("fallback");
|
|
155
|
+
(0, bun_test_1.expect)(args.getString("count")).toBe("3");
|
|
156
|
+
(0, bun_test_1.expect)(args.getString("flag")).toBe("true");
|
|
157
|
+
});
|
|
158
|
+
(0, bun_test_1.it)("getNumber handles native numbers, strings, NaN, and missing", function () {
|
|
159
|
+
var args = (0, scriptRunner_1.createScriptArgs)({ values: { a: 7, b: "8", c: "x" } }).args;
|
|
160
|
+
(0, bun_test_1.expect)(args.getNumber("a")).toBe(7);
|
|
161
|
+
(0, bun_test_1.expect)(args.getNumber("b")).toBe(8);
|
|
162
|
+
(0, bun_test_1.expect)(args.getNumber("c", 1)).toBe(1);
|
|
163
|
+
(0, bun_test_1.expect)(args.getNumber("missing", 99)).toBe(99);
|
|
164
|
+
(0, bun_test_1.expect)(args.getNumber("missing")).toBeUndefined();
|
|
165
|
+
});
|
|
166
|
+
(0, bun_test_1.it)("getBoolean honors native booleans, string truthiness, and fallback", function () {
|
|
167
|
+
var args = (0, scriptRunner_1.createScriptArgs)({ values: { a: true, b: "on", c: "nope" } }).args;
|
|
168
|
+
(0, bun_test_1.expect)(args.getBoolean("a")).toBe(true);
|
|
169
|
+
(0, bun_test_1.expect)(args.getBoolean("b")).toBe(true);
|
|
170
|
+
(0, bun_test_1.expect)(args.getBoolean("c")).toBe(false);
|
|
171
|
+
(0, bun_test_1.expect)(args.getBoolean("missing")).toBe(false);
|
|
172
|
+
(0, bun_test_1.expect)(args.getBoolean("missing", true)).toBe(true);
|
|
173
|
+
});
|
|
174
|
+
(0, bun_test_1.it)("reads undeclared array values via getString/getNumber (first element)", function () {
|
|
175
|
+
var args = (0, scriptRunner_1.createScriptArgs)({ values: { nums: ["3", "4"], tags: ["x", "y"] } }).args;
|
|
176
|
+
(0, bun_test_1.expect)(args.getString("tags")).toBe("x");
|
|
177
|
+
(0, bun_test_1.expect)(args.getNumber("nums")).toBe(3);
|
|
178
|
+
});
|
|
179
|
+
(0, bun_test_1.it)("getStringArray normalizes single values and missing keys", function () {
|
|
180
|
+
var args = (0, scriptRunner_1.createScriptArgs)({ values: { many: ["a", "b"], one: "x" } }).args;
|
|
181
|
+
(0, bun_test_1.expect)(args.getStringArray("one")).toEqual(["x"]);
|
|
182
|
+
(0, bun_test_1.expect)(args.getStringArray("many")).toEqual(["a", "b"]);
|
|
183
|
+
(0, bun_test_1.expect)(args.getStringArray("missing")).toEqual([]);
|
|
184
|
+
});
|
|
185
|
+
(0, bun_test_1.it)("exposes raw values and positional list", function () {
|
|
186
|
+
var args = (0, scriptRunner_1.createScriptArgs)({ positional: ["p"], values: { x: "1" } }).args;
|
|
187
|
+
(0, bun_test_1.expect)(args.raw.x).toBe("1");
|
|
188
|
+
(0, bun_test_1.expect)(args.positional).toEqual(["p"]);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
(0, bun_test_1.describe)("TaskCancelledError", function () {
|
|
193
|
+
(0, bun_test_1.it)("sets the message and name", function () {
|
|
194
|
+
var err = new scriptRunner_1.TaskCancelledError("task-123");
|
|
195
|
+
(0, bun_test_1.expect)(err.message).toBe("Task task-123 was cancelled");
|
|
196
|
+
(0, bun_test_1.expect)(err.name).toBe("TaskCancelledError");
|
|
197
|
+
});
|
|
198
|
+
(0, bun_test_1.it)("is an instance of Error", function () {
|
|
199
|
+
var err = new scriptRunner_1.TaskCancelledError("abc");
|
|
200
|
+
(0, bun_test_1.expect)(err).toBeInstanceOf(Error);
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
(0, bun_test_1.describe)("BackgroundTask model", function () {
|
|
204
|
+
(0, bun_test_1.beforeAll)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
205
|
+
var _a;
|
|
206
|
+
return __generator(this, function (_b) {
|
|
207
|
+
switch (_b.label) {
|
|
208
|
+
case 0:
|
|
209
|
+
if (!(mongoose_1.default.connection.readyState !== 1)) return [3 /*break*/, 2];
|
|
210
|
+
return [4 /*yield*/, mongoose_1.default.connect((_a = process.env.MONGO_URL) !== null && _a !== void 0 ? _a : "mongodb://127.0.0.1/terreno-test")];
|
|
211
|
+
case 1:
|
|
212
|
+
_b.sent();
|
|
213
|
+
_b.label = 2;
|
|
214
|
+
case 2: return [4 /*yield*/, scriptRunner_1.BackgroundTask.deleteMany({})];
|
|
215
|
+
case 3:
|
|
216
|
+
_b.sent();
|
|
217
|
+
return [2 /*return*/];
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}); });
|
|
221
|
+
(0, bun_test_1.afterAll)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
222
|
+
return __generator(this, function (_a) {
|
|
223
|
+
switch (_a.label) {
|
|
224
|
+
case 0: return [4 /*yield*/, scriptRunner_1.BackgroundTask.deleteMany({})];
|
|
225
|
+
case 1:
|
|
226
|
+
_a.sent();
|
|
227
|
+
return [2 /*return*/];
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}); });
|
|
231
|
+
(0, bun_test_1.it)("creates a task with required fields", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
232
|
+
var task;
|
|
233
|
+
return __generator(this, function (_a) {
|
|
234
|
+
switch (_a.label) {
|
|
235
|
+
case 0: return [4 /*yield*/, scriptRunner_1.BackgroundTask.create({ taskType: "test-task" })];
|
|
236
|
+
case 1:
|
|
237
|
+
task = _a.sent();
|
|
238
|
+
(0, bun_test_1.expect)(task.taskType).toBe("test-task");
|
|
239
|
+
(0, bun_test_1.expect)(task.status).toBe("pending");
|
|
240
|
+
(0, bun_test_1.expect)(task.isDryRun).toBe(false);
|
|
241
|
+
(0, bun_test_1.expect)(task.logs).toEqual([]);
|
|
242
|
+
return [2 /*return*/];
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}); });
|
|
246
|
+
(0, bun_test_1.describe)("addLog", function () {
|
|
247
|
+
(0, bun_test_1.it)("appends a log entry and saves", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
248
|
+
var task, reloaded;
|
|
249
|
+
return __generator(this, function (_a) {
|
|
250
|
+
switch (_a.label) {
|
|
251
|
+
case 0: return [4 /*yield*/, scriptRunner_1.BackgroundTask.create({ taskType: "log-test" })];
|
|
252
|
+
case 1:
|
|
253
|
+
task = _a.sent();
|
|
254
|
+
return [4 /*yield*/, task.addLog("info", "step completed")];
|
|
255
|
+
case 2:
|
|
256
|
+
_a.sent();
|
|
257
|
+
return [4 /*yield*/, scriptRunner_1.BackgroundTask.findById(task._id)];
|
|
258
|
+
case 3:
|
|
259
|
+
reloaded = _a.sent();
|
|
260
|
+
(0, bun_test_1.expect)(reloaded === null || reloaded === void 0 ? void 0 : reloaded.logs).toHaveLength(1);
|
|
261
|
+
(0, bun_test_1.expect)(reloaded === null || reloaded === void 0 ? void 0 : reloaded.logs[0].level).toBe("info");
|
|
262
|
+
(0, bun_test_1.expect)(reloaded === null || reloaded === void 0 ? void 0 : reloaded.logs[0].message).toBe("step completed");
|
|
263
|
+
(0, bun_test_1.expect)(reloaded === null || reloaded === void 0 ? void 0 : reloaded.logs[0].timestamp).toBeDefined();
|
|
264
|
+
return [2 /*return*/];
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
}); });
|
|
268
|
+
(0, bun_test_1.it)("appends multiple log entries", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
269
|
+
var task, reloaded;
|
|
270
|
+
return __generator(this, function (_a) {
|
|
271
|
+
switch (_a.label) {
|
|
272
|
+
case 0: return [4 /*yield*/, scriptRunner_1.BackgroundTask.create({ taskType: "multi-log" })];
|
|
273
|
+
case 1:
|
|
274
|
+
task = _a.sent();
|
|
275
|
+
return [4 /*yield*/, task.addLog("info", "first")];
|
|
276
|
+
case 2:
|
|
277
|
+
_a.sent();
|
|
278
|
+
return [4 /*yield*/, task.addLog("warn", "second")];
|
|
279
|
+
case 3:
|
|
280
|
+
_a.sent();
|
|
281
|
+
return [4 /*yield*/, task.addLog("error", "third")];
|
|
282
|
+
case 4:
|
|
283
|
+
_a.sent();
|
|
284
|
+
return [4 /*yield*/, scriptRunner_1.BackgroundTask.findById(task._id)];
|
|
285
|
+
case 5:
|
|
286
|
+
reloaded = _a.sent();
|
|
287
|
+
(0, bun_test_1.expect)(reloaded === null || reloaded === void 0 ? void 0 : reloaded.logs).toHaveLength(3);
|
|
288
|
+
(0, bun_test_1.expect)(reloaded === null || reloaded === void 0 ? void 0 : reloaded.logs[0].level).toBe("info");
|
|
289
|
+
(0, bun_test_1.expect)(reloaded === null || reloaded === void 0 ? void 0 : reloaded.logs[1].level).toBe("warn");
|
|
290
|
+
(0, bun_test_1.expect)(reloaded === null || reloaded === void 0 ? void 0 : reloaded.logs[2].level).toBe("error");
|
|
291
|
+
return [2 /*return*/];
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}); });
|
|
295
|
+
});
|
|
296
|
+
(0, bun_test_1.describe)("updateProgress", function () {
|
|
297
|
+
(0, bun_test_1.it)("sets progress percentage and stage", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
298
|
+
var task, reloaded;
|
|
299
|
+
var _a, _b, _c;
|
|
300
|
+
return __generator(this, function (_d) {
|
|
301
|
+
switch (_d.label) {
|
|
302
|
+
case 0: return [4 /*yield*/, scriptRunner_1.BackgroundTask.create({ taskType: "progress-test" })];
|
|
303
|
+
case 1:
|
|
304
|
+
task = _d.sent();
|
|
305
|
+
return [4 /*yield*/, task.updateProgress(50, "processing", "halfway done")];
|
|
306
|
+
case 2:
|
|
307
|
+
_d.sent();
|
|
308
|
+
return [4 /*yield*/, scriptRunner_1.BackgroundTask.findById(task._id)];
|
|
309
|
+
case 3:
|
|
310
|
+
reloaded = _d.sent();
|
|
311
|
+
(0, bun_test_1.expect)((_a = reloaded === null || reloaded === void 0 ? void 0 : reloaded.progress) === null || _a === void 0 ? void 0 : _a.percentage).toBe(50);
|
|
312
|
+
(0, bun_test_1.expect)((_b = reloaded === null || reloaded === void 0 ? void 0 : reloaded.progress) === null || _b === void 0 ? void 0 : _b.stage).toBe("processing");
|
|
313
|
+
(0, bun_test_1.expect)((_c = reloaded === null || reloaded === void 0 ? void 0 : reloaded.progress) === null || _c === void 0 ? void 0 : _c.message).toBe("halfway done");
|
|
314
|
+
return [2 /*return*/];
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
}); });
|
|
318
|
+
(0, bun_test_1.it)("preserves previous stage and message when not provided", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
319
|
+
var task, reloaded;
|
|
320
|
+
var _a, _b, _c;
|
|
321
|
+
return __generator(this, function (_d) {
|
|
322
|
+
switch (_d.label) {
|
|
323
|
+
case 0: return [4 /*yield*/, scriptRunner_1.BackgroundTask.create({ taskType: "progress-retain" })];
|
|
324
|
+
case 1:
|
|
325
|
+
task = _d.sent();
|
|
326
|
+
return [4 /*yield*/, task.updateProgress(25, "init", "starting")];
|
|
327
|
+
case 2:
|
|
328
|
+
_d.sent();
|
|
329
|
+
return [4 /*yield*/, task.updateProgress(75)];
|
|
330
|
+
case 3:
|
|
331
|
+
_d.sent();
|
|
332
|
+
return [4 /*yield*/, scriptRunner_1.BackgroundTask.findById(task._id)];
|
|
333
|
+
case 4:
|
|
334
|
+
reloaded = _d.sent();
|
|
335
|
+
(0, bun_test_1.expect)((_a = reloaded === null || reloaded === void 0 ? void 0 : reloaded.progress) === null || _a === void 0 ? void 0 : _a.percentage).toBe(75);
|
|
336
|
+
(0, bun_test_1.expect)((_b = reloaded === null || reloaded === void 0 ? void 0 : reloaded.progress) === null || _b === void 0 ? void 0 : _b.stage).toBe("init");
|
|
337
|
+
(0, bun_test_1.expect)((_c = reloaded === null || reloaded === void 0 ? void 0 : reloaded.progress) === null || _c === void 0 ? void 0 : _c.message).toBe("starting");
|
|
338
|
+
return [2 /*return*/];
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
}); });
|
|
342
|
+
});
|
|
343
|
+
(0, bun_test_1.describe)("checkCancellation", function () {
|
|
344
|
+
(0, bun_test_1.it)("does nothing when task is not cancelled", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
345
|
+
var task;
|
|
346
|
+
return __generator(this, function (_a) {
|
|
347
|
+
switch (_a.label) {
|
|
348
|
+
case 0: return [4 /*yield*/, scriptRunner_1.BackgroundTask.create({ status: "running", taskType: "check-cancel" })];
|
|
349
|
+
case 1:
|
|
350
|
+
task = _a.sent();
|
|
351
|
+
return [4 /*yield*/, (0, bun_test_1.expect)(scriptRunner_1.BackgroundTask.checkCancellation(task._id.toString())).resolves.toBeUndefined()];
|
|
352
|
+
case 2:
|
|
353
|
+
_a.sent();
|
|
354
|
+
return [2 /*return*/];
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
}); });
|
|
358
|
+
(0, bun_test_1.it)("throws TaskCancelledError when task is cancelled", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
359
|
+
var task;
|
|
360
|
+
return __generator(this, function (_a) {
|
|
361
|
+
switch (_a.label) {
|
|
362
|
+
case 0: return [4 /*yield*/, scriptRunner_1.BackgroundTask.create({ status: "cancelled", taskType: "check-cancel" })];
|
|
363
|
+
case 1:
|
|
364
|
+
task = _a.sent();
|
|
365
|
+
return [4 /*yield*/, (0, bun_test_1.expect)(scriptRunner_1.BackgroundTask.checkCancellation(task._id.toString())).rejects.toThrow(scriptRunner_1.TaskCancelledError)];
|
|
366
|
+
case 2:
|
|
367
|
+
_a.sent();
|
|
368
|
+
return [2 /*return*/];
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
}); });
|
|
372
|
+
(0, bun_test_1.it)("does nothing when task does not exist", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
373
|
+
var fakeId;
|
|
374
|
+
return __generator(this, function (_a) {
|
|
375
|
+
switch (_a.label) {
|
|
376
|
+
case 0:
|
|
377
|
+
fakeId = new mongoose_1.default.Types.ObjectId().toString();
|
|
378
|
+
return [4 /*yield*/, (0, bun_test_1.expect)(scriptRunner_1.BackgroundTask.checkCancellation(fakeId)).resolves.toBeUndefined()];
|
|
379
|
+
case 1:
|
|
380
|
+
_a.sent();
|
|
381
|
+
return [2 /*return*/];
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
}); });
|
|
385
|
+
});
|
|
386
|
+
});
|
package/package.json
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
},
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@asteasolutions/zod-to-openapi": "^8.5.0",
|
|
8
|
-
"@sentry/bun": "^10.
|
|
8
|
+
"@sentry/bun": "^10.39.0",
|
|
9
9
|
"@sentry/profiling-node": "^10.25.0",
|
|
10
|
-
"@terreno/test": "0.
|
|
10
|
+
"@terreno/test": "0.23.1",
|
|
11
11
|
"@types/qs": "^6.14.0",
|
|
12
12
|
"ajv": "8.18.0",
|
|
13
13
|
"ajv-formats": "^3.0.1",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"passport-jwt": "^4.0.0",
|
|
39
39
|
"passport-local": "^1.0.0",
|
|
40
40
|
"passport-local-mongoose": "^9.0.1",
|
|
41
|
-
"qs": "^6.
|
|
41
|
+
"qs": "^6.15.0",
|
|
42
42
|
"@thream/socketio-jwt": "^3.1.4",
|
|
43
43
|
"scmp": "^2.1.0",
|
|
44
44
|
"socket.io": "^4.8.1",
|
|
@@ -48,12 +48,12 @@
|
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@biomejs/biome": "^2.3.6",
|
|
50
50
|
"@types/bcrypt": "^6.0.0",
|
|
51
|
-
"@types/bun": "^1.
|
|
51
|
+
"@types/bun": "^1.3.8",
|
|
52
52
|
"@types/cors": "^2.8.17",
|
|
53
53
|
"@types/cron": "^2.4.3",
|
|
54
54
|
"@types/express": "^5.0.6",
|
|
55
55
|
"@types/jsonwebtoken": "^9.0.9",
|
|
56
|
-
"@types/lodash": "^4.17.
|
|
56
|
+
"@types/lodash": "^4.17.17",
|
|
57
57
|
"@types/mongodb": "^4.0.7",
|
|
58
58
|
"@types/node": "^25.3.0",
|
|
59
59
|
"@types/on-finished": "^2.3.4",
|
|
@@ -63,14 +63,14 @@
|
|
|
63
63
|
"@types/passport-jwt": "^4.0.1",
|
|
64
64
|
"@types/passport-local": "^1.0.38",
|
|
65
65
|
"@types/sinon": "^21.0.0",
|
|
66
|
-
"@types/supertest": "^
|
|
66
|
+
"@types/supertest": "^7.2.0",
|
|
67
67
|
"mongodb-memory-server": "^11.0.1",
|
|
68
68
|
"mongoose": "8.23.0",
|
|
69
69
|
"sinon": "^21.0.1",
|
|
70
|
-
"supertest": "^7.
|
|
71
|
-
"typedoc": "
|
|
72
|
-
"typescript": "5.9.
|
|
73
|
-
"zod": "^4.3
|
|
70
|
+
"supertest": "^7.2.2",
|
|
71
|
+
"typedoc": "^0.28.17",
|
|
72
|
+
"typescript": "~5.9.2",
|
|
73
|
+
"zod": "^4.4.3"
|
|
74
74
|
},
|
|
75
75
|
"homepage": "https://github.com/FlourishHealth/terreno#readme",
|
|
76
76
|
"keywords": [
|
|
@@ -123,5 +123,5 @@
|
|
|
123
123
|
"updateSnapshot": "bun test --update-snapshots"
|
|
124
124
|
},
|
|
125
125
|
"types": "dist/index.d.ts",
|
|
126
|
-
"version": "0.
|
|
126
|
+
"version": "0.23.1"
|
|
127
127
|
}
|
package/src/api.test.ts
CHANGED
|
@@ -2078,10 +2078,14 @@ describe("@terreno/api", () => {
|
|
|
2078
2078
|
{_id: spinach._id as unknown as mongoose.Types.ObjectId},
|
|
2079
2079
|
{$set: {updated: "2025-06-15T12:00:00.000Z"}}
|
|
2080
2080
|
);
|
|
2081
|
+
const ifUnmodifiedSince = DateTime.fromISO("2025-06-15T11:00:00.000Z").toHTTP();
|
|
2082
|
+
if (!ifUnmodifiedSince) {
|
|
2083
|
+
throw new Error("Expected valid HTTP date");
|
|
2084
|
+
}
|
|
2081
2085
|
|
|
2082
2086
|
const res = await agent
|
|
2083
2087
|
.patch(`/food/${spinach._id}`)
|
|
2084
|
-
.set("If-Unmodified-Since",
|
|
2088
|
+
.set("If-Unmodified-Since", ifUnmodifiedSince)
|
|
2085
2089
|
.send({name: "String Timestamp"})
|
|
2086
2090
|
.expect(409);
|
|
2087
2091
|
|
package/src/auth.test.ts
CHANGED
|
@@ -1175,3 +1175,41 @@ describe("login error and disabled user paths", () => {
|
|
|
1175
1175
|
expect(res.body.title).toContain("disabled");
|
|
1176
1176
|
});
|
|
1177
1177
|
});
|
|
1178
|
+
|
|
1179
|
+
describe("PATCH /me route edge cases", () => {
|
|
1180
|
+
let app: express.Application;
|
|
1181
|
+
let agent: TestAgent;
|
|
1182
|
+
|
|
1183
|
+
beforeEach(async () => {
|
|
1184
|
+
setSystemTime();
|
|
1185
|
+
await setupTestData();
|
|
1186
|
+
app = new TerrenoApp({
|
|
1187
|
+
configureApp: () => {},
|
|
1188
|
+
skipListen: true,
|
|
1189
|
+
userModel: UserModel as any,
|
|
1190
|
+
}).build();
|
|
1191
|
+
agent = supertest.agent(app);
|
|
1192
|
+
});
|
|
1193
|
+
|
|
1194
|
+
afterEach(() => {
|
|
1195
|
+
setSystemTime();
|
|
1196
|
+
});
|
|
1197
|
+
|
|
1198
|
+
it("returns 404 for PATCH /me when authenticated user is deleted from DB", async () => {
|
|
1199
|
+
const loginRes = await agent
|
|
1200
|
+
.post("/auth/login")
|
|
1201
|
+
.send({email: "notAdmin@example.com", password: "password"})
|
|
1202
|
+
.expect(200);
|
|
1203
|
+
const {token, userId} = loginRes.body.data;
|
|
1204
|
+
|
|
1205
|
+
await UserModel.deleteOne({_id: userId});
|
|
1206
|
+
|
|
1207
|
+
const freshAgent = supertest.agent(app);
|
|
1208
|
+
const res = await freshAgent
|
|
1209
|
+
.patch("/auth/me")
|
|
1210
|
+
.set("authorization", `Bearer ${token}`)
|
|
1211
|
+
.send({name: "Updated"});
|
|
1212
|
+
// Without user in DB, should get 401 or 404
|
|
1213
|
+
expect([401, 404]).toContain(res.status);
|
|
1214
|
+
});
|
|
1215
|
+
});
|
package/src/consentApp.test.ts
CHANGED
|
@@ -185,6 +185,32 @@ describe("ConsentApp", () => {
|
|
|
185
185
|
expect(res.body.data[0].agreed).toBe(true);
|
|
186
186
|
});
|
|
187
187
|
|
|
188
|
+
it("populates consentFormId and userId on read", async () => {
|
|
189
|
+
const form = await ConsentForm.create({
|
|
190
|
+
active: true,
|
|
191
|
+
content: new Map([["en", "# Terms"]]),
|
|
192
|
+
order: 1,
|
|
193
|
+
slug: "terms-populated",
|
|
194
|
+
title: "Terms Populated",
|
|
195
|
+
type: "terms",
|
|
196
|
+
version: 1,
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const response = await ConsentResponse.create({
|
|
200
|
+
agreed: true,
|
|
201
|
+
agreedAt: new Date(),
|
|
202
|
+
consentFormId: form._id,
|
|
203
|
+
formVersionSnapshot: 1,
|
|
204
|
+
locale: "en",
|
|
205
|
+
userId: notAdmin._id,
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
const res = await adminAgent.get(`/consent-responses/${response._id}`).expect(200);
|
|
209
|
+
expect(res.body.data.consentFormId.title).toBe("Terms Populated");
|
|
210
|
+
expect(res.body.data.userId.email).toBe(notAdmin.email);
|
|
211
|
+
expect(res.body.data.userId.name).toBe(notAdmin.name);
|
|
212
|
+
});
|
|
213
|
+
|
|
188
214
|
it("blocks non-admins from listing responses", async () => {
|
|
189
215
|
await userAgent.get("/consent-responses").expect(405);
|
|
190
216
|
});
|
package/src/consentApp.ts
CHANGED
|
@@ -17,9 +17,22 @@ import {logger} from "./logger";
|
|
|
17
17
|
import {ConsentForm} from "./models/consentForm";
|
|
18
18
|
import {ConsentResponse} from "./models/consentResponse";
|
|
19
19
|
import {Permissions} from "./permissions";
|
|
20
|
+
import type {PopulatePath} from "./populate";
|
|
20
21
|
import type {TerrenoPlugin} from "./terrenoPlugin";
|
|
21
22
|
import type {ConsentFormDocument} from "./types/consentForm";
|
|
22
23
|
|
|
24
|
+
/** Shared populate config for consent response list/read endpoints. */
|
|
25
|
+
export const consentResponsePopulatePaths: PopulatePath[] = [
|
|
26
|
+
{
|
|
27
|
+
fields: ["title", "slug", "version", "type"],
|
|
28
|
+
path: "consentFormId",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
fields: ["name", "email"],
|
|
32
|
+
path: "userId",
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
|
|
23
36
|
export interface ConsentAppOptions {
|
|
24
37
|
auditTrail?: boolean;
|
|
25
38
|
aiConfig?: {
|
|
@@ -188,12 +201,7 @@ export class ConsentApp implements TerrenoPlugin {
|
|
|
188
201
|
read: [Permissions.IsAdmin],
|
|
189
202
|
update: [],
|
|
190
203
|
},
|
|
191
|
-
populatePaths:
|
|
192
|
-
{
|
|
193
|
-
fields: ["title", "slug", "version", "type"],
|
|
194
|
-
path: "consentFormId",
|
|
195
|
-
},
|
|
196
|
-
],
|
|
204
|
+
populatePaths: consentResponsePopulatePaths,
|
|
197
205
|
})
|
|
198
206
|
);
|
|
199
207
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import {afterEach, beforeEach, describe, expect, it} from "bun:test";
|
|
1
|
+
import {afterEach, beforeEach, describe, expect, it, spyOn} from "bun:test";
|
|
3
2
|
import mongoose, {Schema} from "mongoose";
|
|
4
3
|
|
|
5
4
|
import {Config} from "./config";
|
|
@@ -163,16 +162,15 @@ describe("envConfigurationPlugin", () => {
|
|
|
163
162
|
|
|
164
163
|
// Override Model.find to simulate a DB error inside refreshFromDoc
|
|
165
164
|
// (findOneOrNoneFor falls back to model.find when the findOneOrNone static is absent)
|
|
166
|
-
const
|
|
167
|
-
(TestEnvConfig as any).find = () => {
|
|
165
|
+
const findSpy = spyOn(TestEnvConfig, "find").mockImplementation(() => {
|
|
168
166
|
throw new Error("Simulated DB error");
|
|
169
|
-
};
|
|
167
|
+
});
|
|
170
168
|
|
|
171
169
|
// Trigger the post-findOneAndUpdate hook → refreshFromDoc → findOneOrNoneFor → throws
|
|
172
170
|
await TestEnvConfig.findOneAndUpdate({_id: doc._id}, {$set: {__v: 2}});
|
|
173
171
|
|
|
174
172
|
// Restore immediately
|
|
175
|
-
(
|
|
173
|
+
findSpy.mockRestore();
|
|
176
174
|
|
|
177
175
|
// The catch block should have swallowed the error; cache keeps old value
|
|
178
176
|
expect(Config.get("TERRENO_PLUGIN_KEY")).toBe("cached");
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
2
1
|
import {afterAll, afterEach, beforeEach, describe, expect, it, type Mock, spyOn} from "bun:test";
|
|
3
2
|
import * as Sentry from "@sentry/bun";
|
|
3
|
+
import type {AxiosResponse} from "axios";
|
|
4
4
|
import axios from "axios";
|
|
5
5
|
|
|
6
|
+
import type {APIError} from "../errors";
|
|
6
7
|
import {sendToZoom} from "./zoomNotifier";
|
|
7
8
|
|
|
8
9
|
describe("sendToZoom", () => {
|
|
@@ -11,7 +12,9 @@ describe("sendToZoom", () => {
|
|
|
11
12
|
const ORIGINAL_ENV = process.env;
|
|
12
13
|
|
|
13
14
|
beforeEach(() => {
|
|
14
|
-
mockAxiosPost = spyOn(axios, "post").mockResolvedValue({
|
|
15
|
+
mockAxiosPost = spyOn(axios, "post").mockResolvedValue({
|
|
16
|
+
status: 200,
|
|
17
|
+
} as unknown as AxiosResponse);
|
|
15
18
|
process.env = {...ORIGINAL_ENV};
|
|
16
19
|
process.env.ZOOM_CHAT_WEBHOOKS = undefined;
|
|
17
20
|
(Sentry.captureException as Mock<typeof Sentry.captureException>).mockClear();
|
|
@@ -187,8 +190,8 @@ describe("sendToZoom", () => {
|
|
|
187
190
|
await sendToZoom({body: "err", header: "err"}, {channel: "default", shouldThrow: true});
|
|
188
191
|
throw new Error("Expected sendToZoom to throw APIError");
|
|
189
192
|
} catch (error) {
|
|
190
|
-
expect((error as
|
|
191
|
-
expect((error as
|
|
193
|
+
expect((error as APIError).name).toBe("APIError");
|
|
194
|
+
expect((error as APIError).title).toMatch(/Error posting to Zoom/i);
|
|
192
195
|
}
|
|
193
196
|
expect(mockAxiosPost.mock.calls.length).toBe(1);
|
|
194
197
|
});
|