Don't log warnings when running tests

This commit is contained in:
Vincent 2023-08-30 12:25:35 +02:00 коммит произвёл Vincent
Родитель 9f0d1571b2
Коммит 9e1b0e3c83
2 изменённых файлов: 20 добавлений и 9 удалений

Просмотреть файл

@ -14,6 +14,15 @@ export type FeatureFlagsEnabled = {
FalseDoorTest: boolean; FalseDoorTest: boolean;
}; };
// This function is specifically meant to not execute in tests:
/* c8 ignore next 6 */
const warn: typeof console.warn = (...args) => {
if (process.env.NODE_ENV === "test") {
return;
}
console.warn(...args);
};
export async function isFlagEnabled( export async function isFlagEnabled(
name: keyof FeatureFlagsEnabled, name: keyof FeatureFlagsEnabled,
user?: Session["user"] user?: Session["user"]
@ -23,7 +32,7 @@ export async function isFlagEnabled(
// TODO: Add unit test when changing this code: // TODO: Add unit test when changing this code:
/* c8 ignore next 4 */ /* c8 ignore next 4 */
if (!data) { if (!data) {
console.warn("Feature flag does not exist:", name); warn("Feature flag does not exist:", name);
return false; return false;
} }
@ -40,17 +49,17 @@ export async function isFlagEnabled(
}; };
if (flag.deletedAt) { if (flag.deletedAt) {
console.warn("Flag has been deleted:", flag.name); warn("Flag has been deleted:", flag.name);
return false; return false;
} }
if (flag.expiredAt) { if (flag.expiredAt) {
console.warn("Flag has expired:", flag.name); warn("Flag has expired:", flag.name);
return false; return false;
} }
if (!flag.isEnabled) { if (!flag.isEnabled) {
console.warn("Flag is not enabled:", flag.name); warn("Flag is not enabled:", flag.name);
return false; return false;
} }
@ -59,7 +68,7 @@ export async function isFlagEnabled(
} else if (flag.allowList?.includes(user.email)) { } else if (flag.allowList?.includes(user.email)) {
return true; return true;
} else { } else {
console.warn("User is not on the allow list for flag:", flag.name); warn("User is not on the allow list for flag:", flag.name);
return false; return false;
} }
} }

Просмотреть файл

@ -143,10 +143,12 @@ async function notify(req, res) {
.map((condition) => condition.logId) .map((condition) => condition.logId)
.join(", "); .join(", ");
console.info("Breach alert email was not sent.", { if (process.env.NODE_ENV !== "test") {
name: breachAlert.Name, console.info("Breach alert email was not sent.", {
reason: `The following conditions were not satisfied: ${conditionLogIds}.`, name: breachAlert.Name,
}); reason: `The following conditions were not satisfied: ${conditionLogIds}.`,
});
}
return res.status(200).json({ return res.status(200).json({
info: "Breach loaded into database. Subscribers not notified.", info: "Breach loaded into database. Subscribers not notified.",