Skip to content

Commit

Permalink
feat: added tests to handle edges cases
Browse files Browse the repository at this point in the history
  • Loading branch information
pankajjs committed Jan 6, 2025
1 parent 444e34c commit afea15d
Showing 1 changed file with 76 additions and 1 deletion.
77 changes: 76 additions & 1 deletion test/unit/models/discordactions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const {
removeMemberGroup,
getGroupRoleByName,
getGroupRolesForUser,
skipOnboardingUsersHavingApprovedExtensionRequest,
} = require("../../../models/discordactions");
const {
groupData,
Expand All @@ -63,6 +64,8 @@ const { stubbedModelTaskProgressData } = require("../../fixtures/progress/progre
const { convertDaysToMilliseconds } = require("../../../utils/time");
const { generateUserStatusData } = require("../../fixtures/userStatus/userStatus");
const { userState } = require("../../../constants/userStatus");
const { REQUEST_TYPE, REQUEST_STATE } = require("../../../constants/requests");
const { createRequest } = require("../../../models/requests");

chai.should();

Expand Down Expand Up @@ -1064,6 +1067,7 @@ describe("discordactions", function () {

describe("updateUsersWith31DaysPlusOnboarding", function () {
let fetchStub;
let userId0;

beforeEach(async function () {
fetchStub = sinon.stub(global, "fetch");
Expand All @@ -1087,7 +1091,7 @@ describe("discordactions", function () {
roles: { archived: false, in_discord: true },
};

const userId0 = await addUser(userData[0]);
userId0 = await addUser(userData[0]);
const userId1 = await addUser(userData[1]);
const userId2 = await addUser(userData[2]);

Expand Down Expand Up @@ -1133,6 +1137,48 @@ describe("discordactions", function () {
await cleanDb();
});

it("should add grouponboarding31D when user has an approved extension request but dealine has been passed", async function () {
await createRequest({
type: REQUEST_TYPE.ONBOARDING,
state: REQUEST_STATE.APPROVED,
newEndsOn: Date.now() - convertDaysToMilliseconds(2),
userId: userId0,
});

const res = await updateUsersWith31DaysPlusOnboarding();
expect(res.totalOnboardingUsers31DaysCompleted.count).to.equal(2);
expect(res.totalOnboarding31dPlusRoleApplied.count).to.equal(1);
expect(res.totalOnboarding31dPlusRoleRemoved.count).to.equal(1);
});

it("should add grouponboarding31D when user does not have approved extension request", async function () {
await createRequest({
type: REQUEST_TYPE.ONBOARDING,
state: REQUEST_STATE.PENDING,
newEndsOn: Date.now() + convertDaysToMilliseconds(2),
userId: userId0,
});

const res = await updateUsersWith31DaysPlusOnboarding();
expect(res.totalOnboardingUsers31DaysCompleted.count).to.equal(2);
expect(res.totalOnboarding31dPlusRoleApplied.count).to.equal(1);
expect(res.totalOnboarding31dPlusRoleRemoved.count).to.equal(1);
});

it("should not add grouponboarding31D when user has approved extension request", async function () {
await createRequest({
type: REQUEST_TYPE.ONBOARDING,
state: REQUEST_STATE.APPROVED,
newEndsOn: Date.now() + convertDaysToMilliseconds(2),
userId: userId0,
});

const res = await updateUsersWith31DaysPlusOnboarding();
expect(res.totalOnboardingUsers31DaysCompleted.count).to.equal(1);
expect(res.totalOnboarding31dPlusRoleApplied.count).to.equal(1);
expect(res.totalOnboarding31dPlusRoleRemoved.count).to.equal(1);
});

it("apply, or remove grouponboarding31D", async function () {
const res = await updateUsersWith31DaysPlusOnboarding();

Expand Down Expand Up @@ -1343,4 +1389,33 @@ describe("discordactions", function () {
}
});
});

describe("skipOnboardingUsersHavingApprovedExtensionRequest", function () {
const userId0 = "11111";
const userId1 = "12345";

afterEach(async function () {
sinon.restore();
await cleanDb();
});

it("should return filtered users", async function () {
await createRequest({
state: REQUEST_STATE.APPROVED,
type: REQUEST_TYPE.ONBOARDING,
newEndsOn: Date.now() + convertDaysToMilliseconds(2),
userId: userId0,
});
const users = await skipOnboardingUsersHavingApprovedExtensionRequest([{ id: userId0 }, { id: userId1 }]);
expect(users.length).to.equal(1);
expect(users[0].id).to.equal(userId1);
});

it("should not return filtered users", async function () {
const users = await skipOnboardingUsersHavingApprovedExtensionRequest([{ id: userId0 }, { id: userId1 }]);
expect(users.length).to.equal(2);
expect(users[0].id).to.equal(userId0);
expect(users[1].id).to.equal(userId1);
});
});
});

0 comments on commit afea15d

Please sign in to comment.