@terreno/api 0.17.0 → 0.18.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.
|
@@ -319,4 +319,53 @@ var setupLoader = function () {
|
|
|
319
319
|
}
|
|
320
320
|
});
|
|
321
321
|
}); });
|
|
322
|
+
(0, bun_test_1.it)("mapToObject handles a plain Record (non-Map) env field", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
323
|
+
var col;
|
|
324
|
+
var _a;
|
|
325
|
+
return __generator(this, function (_b) {
|
|
326
|
+
switch (_b.label) {
|
|
327
|
+
case 0:
|
|
328
|
+
col = (_a = mongoose_1.default.connection.db) === null || _a === void 0 ? void 0 : _a.collection("testenvconfigs");
|
|
329
|
+
return [4 /*yield*/, (col === null || col === void 0 ? void 0 : col.insertOne({ env: { TERRENO_PLUGIN_KEY: "plainObj" } }))];
|
|
330
|
+
case 1:
|
|
331
|
+
_b.sent();
|
|
332
|
+
// Trigger refresh via findOneAndUpdate hook
|
|
333
|
+
return [4 /*yield*/, TestEnvConfig.findOneAndUpdate({}, { $set: { __v: 1 } })];
|
|
334
|
+
case 2:
|
|
335
|
+
// Trigger refresh via findOneAndUpdate hook
|
|
336
|
+
_b.sent();
|
|
337
|
+
(0, bun_test_1.expect)(config_1.Config.get("TERRENO_PLUGIN_KEY")).toBe("plainObj");
|
|
338
|
+
return [2 /*return*/];
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
}); });
|
|
342
|
+
(0, bun_test_1.it)("refreshFromDoc logs a warning and does not throw when the model query fails", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
343
|
+
var doc, originalFind;
|
|
344
|
+
return __generator(this, function (_a) {
|
|
345
|
+
switch (_a.label) {
|
|
346
|
+
case 0:
|
|
347
|
+
doc = new TestEnvConfig();
|
|
348
|
+
doc.env.set("TERRENO_PLUGIN_KEY", "initial");
|
|
349
|
+
return [4 /*yield*/, doc.save()];
|
|
350
|
+
case 1:
|
|
351
|
+
_a.sent();
|
|
352
|
+
// Pre-set cache to verify it is NOT overwritten when the hook errors
|
|
353
|
+
config_1.Config.setCachedEnv({ TERRENO_PLUGIN_KEY: "cached" });
|
|
354
|
+
originalFind = TestEnvConfig.find;
|
|
355
|
+
TestEnvConfig.find = function () {
|
|
356
|
+
throw new Error("Simulated DB error");
|
|
357
|
+
};
|
|
358
|
+
// Trigger the post-findOneAndUpdate hook → refreshFromDoc → findOneOrNoneFor → throws
|
|
359
|
+
return [4 /*yield*/, TestEnvConfig.findOneAndUpdate({ _id: doc._id }, { $set: { __v: 2 } })];
|
|
360
|
+
case 2:
|
|
361
|
+
// Trigger the post-findOneAndUpdate hook → refreshFromDoc → findOneOrNoneFor → throws
|
|
362
|
+
_a.sent();
|
|
363
|
+
// Restore immediately
|
|
364
|
+
TestEnvConfig.find = originalFind;
|
|
365
|
+
// The catch block should have swallowed the error; cache keeps old value
|
|
366
|
+
(0, bun_test_1.expect)(config_1.Config.get("TERRENO_PLUGIN_KEY")).toBe("cached");
|
|
367
|
+
return [2 /*return*/];
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
}); });
|
|
322
371
|
});
|
package/package.json
CHANGED
|
@@ -140,4 +140,41 @@ describe("envConfigurationPlugin", () => {
|
|
|
140
140
|
// mapToObject(undefined) returns {}, so Config falls back to the registered default
|
|
141
141
|
expect(Config.get("TERRENO_PLUGIN_KEY")).toBe("fallback");
|
|
142
142
|
});
|
|
143
|
+
|
|
144
|
+
it("mapToObject handles a plain Record (non-Map) env field", async () => {
|
|
145
|
+
// Insert a document with env as a plain object via raw DB operation
|
|
146
|
+
const col = mongoose.connection.db?.collection("testenvconfigs");
|
|
147
|
+
await col?.insertOne({env: {TERRENO_PLUGIN_KEY: "plainObj"}});
|
|
148
|
+
|
|
149
|
+
// Trigger refresh via findOneAndUpdate hook
|
|
150
|
+
await TestEnvConfig.findOneAndUpdate({}, {$set: {__v: 1}});
|
|
151
|
+
|
|
152
|
+
expect(Config.get("TERRENO_PLUGIN_KEY")).toBe("plainObj");
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("refreshFromDoc logs a warning and does not throw when the model query fails", async () => {
|
|
156
|
+
// Seed a document so findOneAndUpdate has a target
|
|
157
|
+
const doc = new TestEnvConfig();
|
|
158
|
+
doc.env.set("TERRENO_PLUGIN_KEY", "initial");
|
|
159
|
+
await doc.save();
|
|
160
|
+
|
|
161
|
+
// Pre-set cache to verify it is NOT overwritten when the hook errors
|
|
162
|
+
Config.setCachedEnv({TERRENO_PLUGIN_KEY: "cached"});
|
|
163
|
+
|
|
164
|
+
// Override Model.find to simulate a DB error inside refreshFromDoc
|
|
165
|
+
// (findOneOrNoneFor falls back to model.find when the findOneOrNone static is absent)
|
|
166
|
+
const originalFind = TestEnvConfig.find;
|
|
167
|
+
(TestEnvConfig as any).find = () => {
|
|
168
|
+
throw new Error("Simulated DB error");
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// Trigger the post-findOneAndUpdate hook → refreshFromDoc → findOneOrNoneFor → throws
|
|
172
|
+
await TestEnvConfig.findOneAndUpdate({_id: doc._id}, {$set: {__v: 2}});
|
|
173
|
+
|
|
174
|
+
// Restore immediately
|
|
175
|
+
(TestEnvConfig as any).find = originalFind;
|
|
176
|
+
|
|
177
|
+
// The catch block should have swallowed the error; cache keeps old value
|
|
178
|
+
expect(Config.get("TERRENO_PLUGIN_KEY")).toBe("cached");
|
|
179
|
+
});
|
|
143
180
|
});
|