Don't log warnings when running tests
This commit is contained in:
Родитель
9f0d1571b2
Коммит
9e1b0e3c83
|
@ -14,6 +14,15 @@ export type FeatureFlagsEnabled = {
|
|||
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(
|
||||
name: keyof FeatureFlagsEnabled,
|
||||
user?: Session["user"]
|
||||
|
@ -23,7 +32,7 @@ export async function isFlagEnabled(
|
|||
// TODO: Add unit test when changing this code:
|
||||
/* c8 ignore next 4 */
|
||||
if (!data) {
|
||||
console.warn("Feature flag does not exist:", name);
|
||||
warn("Feature flag does not exist:", name);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -40,17 +49,17 @@ export async function isFlagEnabled(
|
|||
};
|
||||
|
||||
if (flag.deletedAt) {
|
||||
console.warn("Flag has been deleted:", flag.name);
|
||||
warn("Flag has been deleted:", flag.name);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (flag.expiredAt) {
|
||||
console.warn("Flag has expired:", flag.name);
|
||||
warn("Flag has expired:", flag.name);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!flag.isEnabled) {
|
||||
console.warn("Flag is not enabled:", flag.name);
|
||||
warn("Flag is not enabled:", flag.name);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -59,7 +68,7 @@ export async function isFlagEnabled(
|
|||
} else if (flag.allowList?.includes(user.email)) {
|
||||
return true;
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -143,10 +143,12 @@ async function notify(req, res) {
|
|||
.map((condition) => condition.logId)
|
||||
.join(", ");
|
||||
|
||||
console.info("Breach alert email was not sent.", {
|
||||
name: breachAlert.Name,
|
||||
reason: `The following conditions were not satisfied: ${conditionLogIds}.`,
|
||||
});
|
||||
if (process.env.NODE_ENV !== "test") {
|
||||
console.info("Breach alert email was not sent.", {
|
||||
name: breachAlert.Name,
|
||||
reason: `The following conditions were not satisfied: ${conditionLogIds}.`,
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(200).json({
|
||||
info: "Breach loaded into database. Subscribers not notified.",
|
||||
|
|
Загрузка…
Ссылка в новой задаче