Skip to content

Commit

Permalink
Revert "Mavens getting listed in idle,idle7d+ (#2127)" (#2158)
Browse files Browse the repository at this point in the history
This reverts commit 364068c.
  • Loading branch information
vinit717 authored Sep 16, 2024
1 parent d4d40b1 commit 1c3a1a6
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 362 deletions.
15 changes: 2 additions & 13 deletions models/discordactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const { FIRESTORE_IN_CLAUSE_SIZE } = require("../constants/users");
const discordService = require("../services/discordService");
const { buildTasksQueryForMissedUpdates } = require("../utils/tasks");
const { buildProgressQueryForMissedUpdates } = require("../utils/progresses");
const allMavens = [];

/**
*
Expand Down Expand Up @@ -336,11 +335,6 @@ const updateIdleUsersOnDiscord = async () => {
discordUsers?.forEach((discordUser) => {
const isDeveloper = discordUser.roles.includes(discordDeveloperRoleId);
const haveIdleRole = discordUser.roles.includes(groupIdleRole.role.roleid);
const isMaven = discordUser.roles.includes(discordMavenRoleId);

if (isMaven) {
allMavens.push(discordUser.user.id);
}

if (isDeveloper && haveIdleRole) {
usersHavingIdleRole.push({ userid: discordUser.user.id });
Expand All @@ -355,7 +349,7 @@ const updateIdleUsersOnDiscord = async () => {
if (userData.exists) {
if (isUserArchived) {
totalArchivedUsers++;
} else if (!allMavens.includes(userData.data().discordId)) {
} else {
userStatus.userid = userData.data().discordId;
allIdleUsers.push(userStatus);
}
Expand Down Expand Up @@ -568,11 +562,6 @@ const updateIdle7dUsersOnDiscord = async () => {
discordUsers?.forEach((discordUser) => {
const isDeveloper = discordUser.roles.includes(discordDeveloperRoleId);
const haveIdle7dRole = discordUser.roles.includes(groupIdle7dRoleId);
const isMaven = discordUser.roles.includes(discordMavenRoleId);

if (isMaven) {
allMavens.push(discordUser.user.id);
}

if (isDeveloper && haveIdle7dRole) {
usersHavingIdle7dRole.push({ userid: discordUser.user.id });
Expand All @@ -594,7 +583,7 @@ const updateIdle7dUsersOnDiscord = async () => {
if (userData.exists) {
if (isUserArchived) {
totalArchivedUsers++;
} else if (!allMavens.includes(userData.data().discordId)) {
} else {
userStatus.userid = userData.data().discordId;
allIdle7dUsers.push(userStatus);
}
Expand Down
46 changes: 0 additions & 46 deletions test/fixtures/discordResponse/discord-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,52 +68,6 @@ const getDiscordMembers = [
mute: false,
deaf: false,
},
{
avatar: "",
communication_disabled_until: "",
flags: 0,
is_pending: false,
joined_at: "some_intensional_date", // ISO8601 timestamp
nick: "goliath",
pending: false,
premium_since: null,
roles: ["giant", "hero"],
user: {
id: "1234567",
username: "goliath",
global_name: "goliath",
display_name: "goliath",
avatar: "56yu6567uuju7636w4e6yr7e9utbw8r4", // avatar hash
discriminator: "44551", // 4-digit discord-tag
public_flags: 0,
avatar_decoration: null,
},
mute: false,
deaf: false,
},
{
avatar: "",
communication_disabled_until: "",
flags: 0,
is_pending: false,
joined_at: "some_intensional_date", // ISO8601 timestamp
nick: "goliath-1",
pending: false,
premium_since: null,
roles: ["giant", "hero"],
user: {
id: "2131234453456545656765767876",
username: "goliath-1",
global_name: "goliath-1",
display_name: "goliath-1",
avatar: "56yu6567uuju7636w4e6yr7e9utbw8r4", // avatar hash
discriminator: "44551", // 4-digit discord-tag
public_flags: 0,
avatar_decoration: null,
},
mute: false,
deaf: false,
},
];

const usersFromRds = [
Expand Down
3 changes: 0 additions & 3 deletions test/fixtures/discordactions/discordactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ const groupData = [

const groupIdle7d = { rolename: "group-idle-7d+", roleid: 4, createdBy: "1dad23q23j131j" };

const groupIdle = { rolename: "group-idle", roleid: 3, createdBy: "1dad23q23j131j" };

const roleData = {
roleid: "test-role-id",
userid: "test-user-id",
Expand Down Expand Up @@ -58,5 +56,4 @@ module.exports = {
groupIdle7d,
roleDataFromDiscord,
groupOnboarding31dPlus,
groupIdle,
};
110 changes: 6 additions & 104 deletions test/integration/discordactions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const {
roleDataFromDiscord,
memberGroupData,
groupOnboarding31dPlus,
groupIdle,
} = require("../fixtures/discordactions/discordactions");
const discordServices = require("../../services/discordService");
const { addGroupRoleToMember, addInviteToInviteModel } = require("../../models/discordactions");
Expand Down Expand Up @@ -616,30 +615,9 @@ describe("Discord actions", function () {
let allIds;

beforeEach(async function () {
userData[0] = {
...userData[0],
discordId: "123456789098765432",
discordJoinedAt: "2023-07-31T16:57:53.894000+00:00",
roles: { archived: false, in_discord: true },
};
userData[1] = {
...userData[1],
discordId: "12345678909867666",
discordJoinedAt: "2023-07-31T16:57:53.894000+00:00",
roles: { archived: false, in_discord: true },
};
userData[2] = {
...userData[2],
discordId: "1234567",
discordJoinedAt: "2023-07-31T16:57:53.894000+00:00",
roles: { archived: false, in_discord: true },
};

getDiscordMembers[3] = {
...getDiscordMembers[3],
roles: ["1212121212"],
};

userData[0].roles = { archived: false };
userData[1].roles = { archived: false };
userData[2].roles = { archived: false };
await addUser(userData[0]);
await addUser(userData[1]);
await addUser(userData[2]);
Expand Down Expand Up @@ -680,9 +658,9 @@ describe("Discord actions", function () {
}
expect(res).to.have.status(201);
expect(res.body.message).to.be.equal("All Idle 7d+ Users updated successfully.");
expect(res.body.totalIdle7dUsers).to.be.equal(2);
expect(res.body.totalGroupIdle7dRolesApplied.count).to.be.equal(2);
expect(res.body.totalUserRoleToBeAdded).to.be.equal(2);
expect(res.body.totalIdle7dUsers).to.be.equal(3);
expect(res.body.totalGroupIdle7dRolesApplied.count).to.be.equal(3);
expect(res.body.totalUserRoleToBeAdded).to.be.equal(3);
return done();
});
});
Expand Down Expand Up @@ -978,80 +956,4 @@ describe("Discord actions", function () {
expect(res.body.inviteLink).to.be.equal("discord.gg/asdfdsfsd");
});
});

describe("PUT /discord-actions/group-idle", function () {
let allIds;

beforeEach(async function () {
userData[0] = {
...userData[0],
discordId: "123456789098765432",
discordJoinedAt: "2023-07-31T16:57:53.894000+00:00",
roles: { archived: false, in_discord: true },
};
userData[1] = {
...userData[1],
discordId: "12345678909867666",
discordJoinedAt: "2023-07-31T16:57:53.894000+00:00",
roles: { archived: false, in_discord: true },
};
userData[2] = {
...userData[2],
discordId: "1234567",
discordJoinedAt: "2023-07-31T16:57:53.894000+00:00",
roles: { archived: false, in_discord: true },
};

getDiscordMembers[3] = {
...getDiscordMembers[3],
roles: ["1212121212"],
};

await addUser(userData[0]);
await addUser(userData[1]);
await addUser(userData[2]);

const addUsersPromises = userData.slice(0, 3).map((user) => userModel.add({ ...user }));
const responses = await Promise.all(addUsersPromises);
allIds = responses.map((response) => response.id);

const userStatusPromises = allIds.map(async (userId) => {
await updateUserStatus(userId, generateUserStatusData("IDLE", 1690829925336, 1690829925336));
});
await Promise.all(userStatusPromises);

const addRolesPromises = [discordRoleModel.add(groupIdle)];
await Promise.all(addRolesPromises);

fetchStub.returns(
Promise.resolve({
status: 200,
json: () => Promise.resolve(getDiscordMembers),
})
);
});

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

it("should update Idle Users successfully and return a 201 status code", function (done) {
chai
.request(app)
.put(`/discord-actions/group-idle`)
.set("Cookie", `${cookieName}=${superUserAuthToken}`)
.end((err, res) => {
if (err) {
return done(err);
}
expect(res).to.have.status(201);
expect(res.body.message).to.be.equal("All Idle Users updated successfully.");
expect(res.body.totalIdleUsers).to.be.equal(2);
expect(res.body.totalGroupIdleRolesApplied.count).to.be.equal(2);
expect(res.body.totalUserRoleToBeAdded).to.be.equal(2);
return done();
});
});
});
});
10 changes: 5 additions & 5 deletions test/integration/external-accounts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ describe("External Accounts", function () {
expect(res).to.have.status(200);
expect(res.body).to.deep.equal({
rdsUsers: 3,
discordUsers: 5,
discordUsers: 3,
userUpdatedWithInDiscordFalse: 0,
usersMarkedUnArchived: 1,
message: "Data Sync Complete",
Expand Down Expand Up @@ -344,7 +344,7 @@ describe("External Accounts", function () {
usersArchivedCount: 1,
usersUnArchivedCount: 0,
totalUsersProcessed: 2,
rdsDiscordServerUsers: 5,
rdsDiscordServerUsers: 3,
backlogTasksCount: 2,
});
});
Expand All @@ -370,7 +370,7 @@ describe("External Accounts", function () {
usersArchivedCount: 0,
usersUnArchivedCount: 0,
totalUsersProcessed: 2,
rdsDiscordServerUsers: 5,
rdsDiscordServerUsers: 3,
backlogTasksCount: 0,
});
});
Expand All @@ -396,7 +396,7 @@ describe("External Accounts", function () {
usersArchivedCount: 0,
usersUnArchivedCount: 1,
totalUsersProcessed: 2,
rdsDiscordServerUsers: 5,
rdsDiscordServerUsers: 3,
backlogTasksCount: 0,
});
});
Expand All @@ -422,7 +422,7 @@ describe("External Accounts", function () {
usersArchivedCount: 0,
usersUnArchivedCount: 0,
totalUsersProcessed: 1,
rdsDiscordServerUsers: 5,
rdsDiscordServerUsers: 3,
backlogTasksCount: 0,
});
});
Expand Down
Loading

0 comments on commit 1c3a1a6

Please sign in to comment.