Skip to content

Commit

Permalink
fixing user resolver test
Browse files Browse the repository at this point in the history
  • Loading branch information
kkatusic committed Nov 21, 2024
1 parent ae87169 commit ddaef95
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 98 deletions.
104 changes: 8 additions & 96 deletions src/resolvers/userResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,10 +613,10 @@ function updateUserTestCases() {
const updateUserData = {
firstName: 'firstName',
lastName: 'lastName',
email: '[email protected]',
location: 'location',
email: user.email, // email should not be updated because verification is required
avatar: 'pinata address',
url: 'website url',
isFirstUpdate: true, // bypassing verification of email
};
const result = await axios.post(
graphqlUrl,
Expand Down Expand Up @@ -652,10 +652,9 @@ function updateUserTestCases() {
const updateUserData = {
firstName: 'firstName',
lastName: 'lastName',
email: '[email protected]',
email: user.email, // email should not be updated because verification is required
avatar: 'pinata address',
url: 'website url',
isFirstUpdate: true, // bypassing verification of email
};
const result = await axios.post(
graphqlUrl,
Expand Down Expand Up @@ -690,7 +689,7 @@ function updateUserTestCases() {
const user = await saveUserDirectlyToDb(generateRandomEtheriumAddress());
const accessToken = await generateTestAccessToken(user.id);
const updateUserData = {
email: '[email protected]',
email: user.email, // email should not be updated because verification is required
avatar: 'pinata address',
url: 'website url',
};
Expand All @@ -712,66 +711,16 @@ function updateUserTestCases() {
errorMessages.BOTH_FIRST_NAME_AND_LAST_NAME_CANT_BE_EMPTY,
);
});
it('should fail when email is invalid first case', async () => {
const user = await saveUserDirectlyToDb(generateRandomEtheriumAddress());
const accessToken = await generateTestAccessToken(user.id);
const updateUserData = {
firstName: 'firstName',
email: 'giveth',
avatar: 'pinata address',
url: 'website url',
isFirstUpdate: true, // bypassing verification of email
};
const result = await axios.post(
graphqlUrl,
{
query: updateUser,
variables: updateUserData,
},
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
},
);

assert.equal(result.data.errors[0].message, errorMessages.INVALID_EMAIL);
});
it('should fail when email is invalid second case', async () => {
const user = await saveUserDirectlyToDb(generateRandomEtheriumAddress());
const accessToken = await generateTestAccessToken(user.id);
const updateUserData = {
firstName: 'firstName',
email: 'giveth @ giveth.com',
avatar: 'pinata address',
url: 'website url',
isFirstUpdate: true, // bypassing verification of email
};
const result = await axios.post(
graphqlUrl,
{
query: updateUser,
variables: updateUserData,
},
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
},
);

assert.equal(result.data.errors[0].message, errorMessages.INVALID_EMAIL);
});
it('should fail when sending empty string for firstName', async () => {
const user = await saveUserDirectlyToDb(generateRandomEtheriumAddress());
const accessToken = await generateTestAccessToken(user.id);
const updateUserData = {
firstName: '',
lastName: 'test lastName',
email: 'giveth @ giveth.com',
email: user.email, // email should not be updated because verification is required
avatar: 'pinata address',
url: 'website url',
isFirstUpdate: true, // bypassing verification of email
};
const result = await axios.post(
graphqlUrl,
Expand All @@ -797,10 +746,9 @@ function updateUserTestCases() {
const updateUserData = {
lastName: '',
firstName: 'firstName',
email: 'giveth @ giveth.com',
email: user.email, // email should not be updated because verification is required
avatar: 'pinata address',
url: 'website url',
isFirstUpdate: true, // bypassing verification of email
};
const result = await axios.post(
graphqlUrl,
Expand Down Expand Up @@ -829,11 +777,10 @@ function updateUserTestCases() {
await user.save();
const accessToken = await generateTestAccessToken(user.id);
const updateUserData = {
email: '[email protected]',
email: user.email, // email should not be updated because verification is required
avatar: 'pinata address',
url: 'website url',
lastName: new Date().getTime().toString(),
isFirstUpdate: true, // bypassing verification of email
};
const result = await axios.post(
graphqlUrl,
Expand Down Expand Up @@ -869,11 +816,10 @@ function updateUserTestCases() {
await user.save();
const accessToken = await generateTestAccessToken(user.id);
const updateUserData = {
email: '[email protected]',
email: user.email, // email should not be updated because verification is required
avatar: 'pinata address',
url: 'website url',
firstName: new Date().getTime().toString(),
isFirstUpdate: true, // bypassing verification of email
};
const result = await axios.post(
graphqlUrl,
Expand All @@ -900,40 +846,6 @@ function updateUserTestCases() {
assert.equal(updatedUser?.name, updateUserData.firstName + ' ' + lastName);
assert.equal(updatedUser?.lastName, lastName);
});

it('should accept empty string for all fields except email', async () => {
const user = await saveUserDirectlyToDb(generateRandomEtheriumAddress());
const accessToken = await generateTestAccessToken(user.id);
const updateUserData = {
firstName: 'test firstName',
lastName: 'test lastName',
avatar: '',
url: '',
isFirstUpdate: true, // bypassing verification of email
};
const result = await axios.post(
graphqlUrl,
{
query: updateUser,
variables: updateUserData,
},
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
},
);
assert.isTrue(result.data.data.updateUser);
const updatedUser = await User.findOne({
where: {
id: user.id,
},
});
assert.equal(updatedUser?.firstName, updateUserData.firstName);
assert.equal(updatedUser?.lastName, updateUserData.lastName);
assert.equal(updatedUser?.avatar, updateUserData.avatar);
assert.equal(updatedUser?.url, updateUserData.url);
});
}

function userEmailVerification() {
Expand Down
2 changes: 0 additions & 2 deletions test/graphqlQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,6 @@ export const updateUser = `
$firstName: String
$avatar: String
$newUser: Boolean
$isFirstUpdate: Boolean
) {
updateUser(
url: $url
Expand All @@ -1347,7 +1346,6 @@ export const updateUser = `
lastName: $lastName
avatar: $avatar
newUser: $newUser
isFirstUpdate: $isFirstUpdate
)
}
`;
Expand Down

0 comments on commit ddaef95

Please sign in to comment.