Skip to content

Commit

Permalink
make mongo optional in pre-mod filter so tests can run
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-funk committed Feb 14, 2025
1 parent 9013bbd commit a8cec89
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 69 deletions.
4 changes: 2 additions & 2 deletions server/src/core/server/services/users/emailPremodFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const emailIsOnAutoBanList = (
};

export const shouldPremodDueToLikelySpamEmail = async (
mongo: MongoContext,
mongo: MongoContext | undefined = undefined,
tenant: Readonly<Tenant>,
user: Readonly<User>
) => {
Expand Down Expand Up @@ -121,7 +121,7 @@ export const shouldPremodDueToLikelySpamEmail = async (
EMAIL_PREMOD_FILTER_PERIOD_LIMIT
),
// premod email aliases if the feature is enabled
tenant?.premoderateEmailAddress?.emailAliases?.enabled
tenant?.premoderateEmailAddress?.emailAliases?.enabled && mongo
? await emailIsAnAliasOfExistingUser(mongo, tenant, user.email)
: false,
];
Expand Down
134 changes: 67 additions & 67 deletions server/src/core/server/services/users/user.emailPremodFilter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
// import {
// createTenantFixture,
// createUserFixture,
// } from "coral-server/test/fixtures";
import {
createTenantFixture,
createUserFixture,
} from "coral-server/test/fixtures";

// import {
// EMAIL_PREMOD_FILTER_PERIOD_LIMIT,
// shouldPremodDueToLikelySpamEmail,
// } from "./emailPremodFilter";
import {
EMAIL_PREMOD_FILTER_PERIOD_LIMIT,
shouldPremodDueToLikelySpamEmail,
} from "./emailPremodFilter";

// const tooManyPeriodsEmail = "[email protected]";
// const justEnoughPeriodsEmail = "[email protected]";
// const noPeriodsEmail = "[email protected]";
const tooManyPeriodsEmail = "[email protected]";
const justEnoughPeriodsEmail = "[email protected]";
const noPeriodsEmail = "[email protected]";

// it("does not premod filter emails when feature is disabled", () => {
// const tenant = createTenantFixture({
// premoderateEmailAddress: {
// tooManyPeriods: {
// enabled: false,
// },
// },
// });
it("does not premod filter emails when feature is disabled", () => {
const tenant = createTenantFixture({
premoderateEmailAddress: {
tooManyPeriods: {
enabled: false,
},
},
});

// const user = createUserFixture({
// email: tooManyPeriodsEmail,
// });
const user = createUserFixture({
email: tooManyPeriodsEmail,
});

// const result = shouldPremodDueToLikelySpamEmail(tenant, user);
// expect(!result);
// });
const result = shouldPremodDueToLikelySpamEmail(undefined, tenant, user);
expect(!result);
});

// it(`does not premod filter emails when feature enabled and has less than ${EMAIL_PREMOD_FILTER_PERIOD_LIMIT} periods`, () => {
// const tenant = createTenantFixture({
// premoderateEmailAddress: {
// tooManyPeriods: {
// enabled: true,
// },
// },
// });
it(`does not premod filter emails when feature enabled and has less than ${EMAIL_PREMOD_FILTER_PERIOD_LIMIT} periods`, () => {
const tenant = createTenantFixture({
premoderateEmailAddress: {
tooManyPeriods: {
enabled: true,
},
},
});

// const user = createUserFixture({
// email: justEnoughPeriodsEmail,
// });
const user = createUserFixture({
email: justEnoughPeriodsEmail,
});

// const result = shouldPremodDueToLikelySpamEmail(tenant, user);
// expect(result);
// });
const result = shouldPremodDueToLikelySpamEmail(undefined, tenant, user);
expect(result);
});

// it(`does not premod filter emails when feature enabled and has no periods`, () => {
// const tenant = createTenantFixture({
// premoderateEmailAddress: {
// tooManyPeriods: {
// enabled: true,
// },
// },
// });
it(`does not premod filter emails when feature enabled and has no periods`, () => {
const tenant = createTenantFixture({
premoderateEmailAddress: {
tooManyPeriods: {
enabled: true,
},
},
});

// const user = createUserFixture({
// email: noPeriodsEmail,
// });
const user = createUserFixture({
email: noPeriodsEmail,
});

// const result = shouldPremodDueToLikelySpamEmail(tenant, user);
// expect(result);
// });
const result = shouldPremodDueToLikelySpamEmail(undefined, tenant, user);
expect(result);
});

// it(`does premod filter emails when feature is enabled and has too many (${EMAIL_PREMOD_FILTER_PERIOD_LIMIT} or more) periods`, () => {
// const tenant = createTenantFixture({
// premoderateEmailAddress: {
// tooManyPeriods: {
// enabled: true,
// },
// },
// });
it(`does premod filter emails when feature is enabled and has too many (${EMAIL_PREMOD_FILTER_PERIOD_LIMIT} or more) periods`, () => {
const tenant = createTenantFixture({
premoderateEmailAddress: {
tooManyPeriods: {
enabled: true,
},
},
});

// const user = createUserFixture({
// email: tooManyPeriodsEmail,
// });
const user = createUserFixture({
email: tooManyPeriodsEmail,
});

// const result = shouldPremodDueToLikelySpamEmail(tenant, user);
// expect(result);
// });
const result = shouldPremodDueToLikelySpamEmail(undefined, tenant, user);
expect(result);
});

0 comments on commit a8cec89

Please sign in to comment.