Skip to content

Commit 7c2cea9

Browse files
authored
Merge pull request #2231 from Real-Dev-Squad/develop
Dev to main
2 parents f2a949e + 9ede915 commit 7c2cea9

File tree

3 files changed

+39
-23
lines changed

3 files changed

+39
-23
lines changed

models/users.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ const getJoinData = async (userId) => {
114114
const joinData = await joinModel.where("userId", "==", userId).limit(1).get();
115115
joinData.forEach((data) => {
116116
userData.push({
117-
id: data.id,
118117
...data.data(),
118+
id: data.id,
119119
});
120120
});
121121
return userData;
@@ -229,7 +229,7 @@ const fetchPaginatedUsers = async (query) => {
229229
const userId = doc.id;
230230
if (!userMap.has(userId)) {
231231
userMap.set(userId, doc.data());
232-
allUsers.push({ id: userId, ...doc.data() });
232+
allUsers.push({ ...doc.data(), id: userId });
233233
}
234234
});
235235
};
@@ -271,8 +271,8 @@ const fetchUsers = async (usernames = []) => {
271271
snapshots.forEach((snapshot) => {
272272
snapshot.forEach((doc) => {
273273
users.push({
274-
id: doc.id,
275274
...doc.data(),
275+
id: doc.id,
276276
});
277277
});
278278
});
@@ -329,8 +329,8 @@ const fetchUser = async ({ userId = null, username = null, githubUsername = null
329329
return {
330330
userExists: !!userData,
331331
user: {
332-
id,
333332
...userData,
333+
id,
334334
},
335335
};
336336
} catch (err) {
@@ -495,7 +495,7 @@ const fetchUserSkills = async (id) => {
495495

496496
if (!data.empty) {
497497
data.forEach((doc) => {
498-
skills.push({ id: doc.id, ...doc.data() });
498+
skills.push({ ...doc.data(), id: doc.id });
499499
});
500500
}
501501
return { skills };
@@ -594,8 +594,8 @@ const getUsersBasedOnFilter = async (query) => {
594594
const snapshot = await userModel.where(`roles.${roleQuery}`, "==", true).get();
595595
snapshot.forEach((doc) => {
596596
filteredUsers.push({
597-
id: doc.id,
598597
...doc.data(),
598+
id: doc.id,
599599
});
600600
});
601601

@@ -610,8 +610,8 @@ const getUsersBasedOnFilter = async (query) => {
610610
const snapshot = await userModel.where("discordId", "!=", null).get();
611611
snapshot.forEach((doc) => {
612612
filteredUsers.push({
613-
id: doc.id,
614613
...doc.data(),
614+
id: doc.id,
615615
});
616616
});
617617

@@ -654,8 +654,8 @@ const getDiscordUsers = async () => {
654654
const userData = user.data();
655655
if (userData?.discordId)
656656
users.push({
657-
id: user.id,
658657
...userData,
658+
id: user.id,
659659
});
660660
});
661661
return users;
@@ -732,8 +732,8 @@ const fetchUserByIds = async (userIds = []) => {
732732
documents.forEach((snapshot) => {
733733
if (snapshot.exists) {
734734
users.push({
735-
id: snapshot.id,
736735
...snapshot.data(),
736+
id: snapshot.id,
737737
});
738738
}
739739
});
@@ -788,8 +788,8 @@ const getUsersByRole = async (role) => {
788788
usersRef.docs.forEach((user) => {
789789
const userData = user.data();
790790
users.push({
791-
id: user.id,
792791
...userData,
792+
id: user.id,
793793
});
794794
});
795795
return users;
@@ -833,8 +833,8 @@ const fetchUserForKeyValue = async (documentKey, value) => {
833833
const userData = user.data();
834834
if (userData)
835835
users.push({
836-
id: user.id,
837836
...userData,
837+
id: user.id,
838838
});
839839
});
840840
return users;
@@ -866,8 +866,8 @@ const fetchUsersListForMultipleValues = async (documentKey, valueList) => {
866866
const userData = user.data();
867867
if (userData)
868868
users.push({
869-
id: user.id,
870869
...userData,
870+
id: user.id,
871871
});
872872
});
873873
}
@@ -890,8 +890,8 @@ const getNonNickNameSyncedUsers = async () => {
890890
const userData = user.data();
891891
if (userData?.discordId)
892892
users.push({
893-
id: user.id,
894893
...userData,
894+
id: user.id,
895895
});
896896
});
897897
return users;

test/integration/external-accounts.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,9 @@ describe("External Accounts", function () {
308308
});
309309

310310
it("Should Archive Users With Archived as False and Not in RDS Discord Server", async function () {
311-
await userModel.add(usersFromRds[4]); // nonArchivedAndNotInDiscord
311+
const doc = await userModel.add(usersFromRds[4]); // nonArchivedAndNotInDiscord
312312

313-
const userId = usersFromRds[4].id;
313+
const userId = doc.id;
314314
const task1 = {
315315
assignee: userId,
316316
status: "ACTIVE",

test/integration/taskRequests.test.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ describe("Task Requests", function () {
10191019
.request(app)
10201020
.post(url)
10211021
.set("cookie", `${cookieName}=${jwt}`)
1022-
.send(mockData.taskRequestData);
1022+
.send({ ...mockData.taskRequestData, userId });
10231023
expect(res).to.have.status(201);
10241024
expect(res.body.message).to.equal("Task request successful.");
10251025
});
@@ -1031,7 +1031,7 @@ describe("Task Requests", function () {
10311031
.request(app)
10321032
.post(url)
10331033
.set("cookie", `${cookieName}=${jwt}`)
1034-
.send(mockData.taskRequestData);
1034+
.send({ ...mockData.taskRequestData, userId });
10351035
expect(res).to.have.status(200);
10361036
expect(res.body.message).to.equal("Task request successful.");
10371037
});
@@ -1043,13 +1043,18 @@ describe("Task Requests", function () {
10431043
.request(app)
10441044
.post(url)
10451045
.set("cookie", `${cookieName}=${jwt}`)
1046-
.send(mockData.taskRequestData);
1046+
.send({ ...mockData.taskRequestData, userId });
10471047
expect(res).to.have.status(409);
10481048
expect(res.body.message).to.equal("Task exists for the given issue.");
10491049
});
10501050

10511051
it("should allow users to request the same task (Assignment)", async function () {
1052-
const requestData = { ...mockData.taskRequestData, requestType: TASK_REQUEST_TYPE.ASSIGNMENT, taskId: "abc" };
1052+
const requestData = {
1053+
...mockData.taskRequestData,
1054+
requestType: TASK_REQUEST_TYPE.ASSIGNMENT,
1055+
taskId: "abc",
1056+
userId,
1057+
};
10531058
fetchTaskStub.resolves({ taskData: { ...taskData, id: requestData.taskId } });
10541059
createRequestStub.resolves({ id: "request123", taskRequest: mockData.existingTaskRequest, isCreate: false });
10551060
const res = await chai.request(app).post(url).set("cookie", `${cookieName}=${jwt}`).send(requestData);
@@ -1061,6 +1066,7 @@ describe("Task Requests", function () {
10611066
const requestData = {
10621067
...mockData.taskRequestData,
10631068
externalIssueUrl: "https://api.github.com/repos/Real-Dev-Squad/website/atus/issues/1564672",
1069+
userId,
10641070
};
10651071
const res = await chai.request(app).post(url).set("cookie", `${cookieName}=${jwt}`).send(requestData);
10661072
expect(res.body.message).to.equal("Issue does not exist");
@@ -1073,7 +1079,7 @@ describe("Task Requests", function () {
10731079
.request(app)
10741080
.post(url)
10751081
.set("cookie", `${cookieName}=${jwt}`)
1076-
.send(mockData.taskRequestData);
1082+
.send({ ...mockData.taskRequestData, userId });
10771083
expect(res.body.message).to.equal("Issue does not exist");
10781084
expect(res).to.have.status(400);
10791085
});
@@ -1082,6 +1088,7 @@ describe("Task Requests", function () {
10821088
const requestData = {
10831089
...mockData.taskRequestData,
10841090
proposedStartDate: mockData.taskRequestData.proposedDeadline + 10000,
1091+
userId,
10851092
};
10861093
const res = await chai.request(app).post(url).set("cookie", `${cookieName}=${jwt}`).send(requestData);
10871094
expect(res.body.message).to.equal("Task deadline cannot be before the start date");
@@ -1096,15 +1103,20 @@ describe("Task Requests", function () {
10961103
});
10971104

10981105
it("should handle user not found", async function () {
1099-
const requestData = { ...mockData.taskRequestData };
1106+
const requestData = { ...mockData.taskRequestData, userId };
11001107
getUsernameStub.resolves(null);
11011108
const res = await chai.request(app).post(url).set("cookie", `${cookieName}=${jwt}`).send(requestData);
11021109
expect(res.body.message).to.equal("User not found");
11031110
expect(res).to.have.status(400);
11041111
});
11051112

11061113
it("should handle task not found (Assignment)", async function () {
1107-
const requestData = { ...mockData.taskRequestData, taskId: "abc", requestType: TASK_REQUEST_TYPE.ASSIGNMENT };
1114+
const requestData = {
1115+
...mockData.taskRequestData,
1116+
taskId: "abc",
1117+
requestType: TASK_REQUEST_TYPE.ASSIGNMENT,
1118+
userId,
1119+
};
11081120
fetchTaskStub.resolves({ taskData: null });
11091121
const res = await chai.request(app).post(url).set("cookie", `${cookieName}=${jwt}`).send(requestData);
11101122
expect(res).to.have.status(400);
@@ -1119,7 +1131,11 @@ describe("Task Requests", function () {
11191131
isCreate: true,
11201132
alreadyRequesting: false,
11211133
});
1122-
await chai.request(app).post(url).set("cookie", `${cookieName}=${jwt}`).send(mockData.taskRequestData);
1134+
await chai
1135+
.request(app)
1136+
.post(url)
1137+
.set("cookie", `${cookieName}=${jwt}`)
1138+
.send({ ...mockData.taskRequestData, userId });
11231139
const logsRef = await logsModel.where("type", "==", "taskRequests").get();
11241140
let taskRequestLogs;
11251141
logsRef.forEach((data) => {

0 commit comments

Comments
 (0)