Skip to content

Commit

Permalink
test: enhance test report
Browse files Browse the repository at this point in the history
add **/* istanbul ignore next */** comment for catch blocks which are n't required testing
  • Loading branch information
Sunny-unik committed Dec 12, 2023
1 parent 98c3947 commit cbc1b93
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
56 changes: 31 additions & 25 deletions src/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ export default class UserController {
.then((users) => {
result = { total: users.length, data: users };
})
.catch((error) => {
result = {
error,
TimeStamp: Date(),
handlerLocation: 'UserController.getUsers',
};
});
.catch(
/* istanbul ignore next */ (error) => {
result = {
error,
TimeStamp: Date(),
handlerLocation: 'UserController.getUsers',
};
}
);
return result;
}

Expand All @@ -29,13 +31,15 @@ export default class UserController {
.findOne({ _id: id })
.select(query ? query : '_id name email')
.then((user) => (result = { data: user }))
.catch((error) => {
result = {
error,
TimeStamp: Date(),
handlerLocation: 'UserController.getUser',
};
});
.catch(
/* istanbul ignore next */ (error) => {
result = {
error,
TimeStamp: Date(),
handlerLocation: 'UserController.getUser',
};
}
);
return result;
}

Expand All @@ -44,7 +48,7 @@ export default class UserController {
const hashPassword = await bcrypt.hash(data.password, 10);
const schema = await new userSchema({ ...data, password: hashPassword });
return await schema.save();
} catch (err) {
} catch (err) /* istanbul ignore next */ {
throw {
error: err,
TimeStamp: Date(),
Expand Down Expand Up @@ -74,7 +78,7 @@ export default class UserController {
...(user ? { id: user._id } : {}),
message: 'Otp sent to your mail address, please check.',
};
} catch (err) {
} catch (err) /* istanbul ignore next */ {
result = err.handlerLocation
? err
: {
Expand All @@ -84,14 +88,16 @@ export default class UserController {
};
}
})
.catch((error) => {
console.log(error);
result = {
error: error,
TimeStamp: Date(),
handlerLocation: 'UserController.verifyMailAddress.SendMail',
};
});
.catch(
/* istanbul ignore next */ (error) => {
console.log(error);
result = {
error: error,
TimeStamp: Date(),
handlerLocation: 'UserController.verifyMailAddress.SendMail',
};
}
);
return result;
}

Expand All @@ -108,7 +114,7 @@ export default class UserController {
? undefined
: { customMessage: 'Invalid OTP' },
};
} catch (err) {
} catch (err) /* istanbul ignore next */ {
result = {
error: err,
TimeStamp: Date(),
Expand Down
2 changes: 1 addition & 1 deletion src/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default async () => {
const { host, port, name } = conn.connection;

console.log(`MongoDB Connected at mongodb://${host}/${port}, DB: ${name}`);
} catch (error) {
} catch (error) /* istanbul ignore next */ {
console.error('\x1b[31m%s\x1b[0m', `Error: ${error}`);
process.exit();
}
Expand Down

0 comments on commit cbc1b93

Please sign in to comment.