fix(test): add regression tests for invites

This commit is contained in:
zkldi
2022-09-30 11:21:25 +01:00
parent c7005dd678
commit 3dd7737096
+43
View File
@@ -0,0 +1,43 @@
import { GetTotalAllowedInvites } from "./invites";
import { ONE_MONTH } from "lib/constants/time";
import { ServerConfig } from "lib/setup/config";
import t from "tap";
import { mkFakeUser } from "test-utils/misc";
t.test("#GetTotalAllowedInvites", (t) => {
t.test("Should give the user more invites each month", (t) => {
t.equal(
GetTotalAllowedInvites(mkFakeUser(1, { joinDate: Date.now() })),
0,
"Should return 0 for a non-alpha/beta tester user who joined today."
);
t.equal(
GetTotalAllowedInvites(mkFakeUser(1, { joinDate: Date.now(), badges: ["beta"] })),
ServerConfig.INVITE_CODE_CONFIG?.BETA_USER_BONUS,
"Should return BETA_USER_BONUS for a beta tester user who joined today."
);
t.equal(
GetTotalAllowedInvites(mkFakeUser(1, { joinDate: Date.now(), badges: ["alpha"] })),
ServerConfig.INVITE_CODE_CONFIG?.BETA_USER_BONUS,
"Should return BETA_USER_BONUS for a alpha tester user who joined today."
);
t.equal(
GetTotalAllowedInvites(mkFakeUser(1, { joinDate: Date.now() - ONE_MONTH })),
ServerConfig.INVITE_CODE_CONFIG?.BATCH_SIZE,
"Should return BATCH_SIZE for a user who joined a month ago."
);
t.equal(
GetTotalAllowedInvites(mkFakeUser(1, { joinDate: Date.now() - ONE_MONTH * 2 })),
(ServerConfig.INVITE_CODE_CONFIG?.BATCH_SIZE ?? 0) * 2,
"Should return 2 * BATCH_SIZE for a user who joined two months ago."
);
t.equal(GetTotalAllowedInvites(mkFakeUser(1, { joinDate: 1638316800000 })), Infinity);
t.end();
});
t.end();
});