Skip to content

Commit

Permalink
Merge pull request #469 from SquareTable/468-remove-extra-information…
Browse files Browse the repository at this point in the history
…-from-userlibfilteruserinformationtosend

Filter extra information like __v and _id from filterUserInformationToSend
  • Loading branch information
Sebastian-Webster authored Nov 10, 2024
2 parents 17b6384 + abb62fb commit 035c5fb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
10 changes: 5 additions & 5 deletions libraries/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ class User {
'authenticationFactorsEnabled',
'MFAEmail',
'followers',
'following'
'following',
'__v',
'_id',
'totalLikes',
'settings'
]

const followers = userObject.followers.length;
const following = userObject.following.length;

console.log('Followers length:', followers, ' | Followers Type:', typeof followers)

notIncludedKeys.forEach(x => delete userObject[x])

userObject.followers = followers
userObject.following = following

userObject._id = userObject._id.toString()

return userObject;
}

Expand Down
3 changes: 1 addition & 2 deletions tests/user/signin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ describe('When Email 2FA is not enabled', () => {
}

test('if login works', async () => {
expect.assertions(12);
expect.assertions(11);

await new User(userData).save();

Expand Down Expand Up @@ -343,7 +343,6 @@ describe('When Email 2FA is not enabled', () => {
expect(includesNotIncludedKey).toBe(false);
expect(typeof returned.data.data.followers).toBe("number");
expect(typeof returned.data.data.following).toBe("number");
expect(typeof returned.data.data._id).toBe("string");
//End of test if correct user data gets returned


Expand Down
3 changes: 1 addition & 2 deletions tests/user/signup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ test('if signup fails if a user with the same name already exists', async () =>

for (const validUserEmail of VALID_EMAILS) {
test(`if user account creation is successful with correct inputs. Email tested: ${validUserEmail}`, async () => {
expect.assertions(21);
expect.assertions(20);

const benchmarkUserData = {
name: validName,
Expand Down Expand Up @@ -344,7 +344,6 @@ for (const validUserEmail of VALID_EMAILS) {
expect(includesNotIncludedKey).toBe(false);
expect(typeof returned.data.data.followers).toBe("number");
expect(typeof returned.data.data.following).toBe("number");
expect(typeof returned.data.data._id).toBe("string");
expect(await DB.changedCollections()).toIncludeSameMembers(['User', 'RefreshToken'])
})
}
Expand Down

0 comments on commit 035c5fb

Please sign in to comment.