Skip to content

Commit

Permalink
no e-mails when run by Playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
hsc-nue committed Oct 6, 2023
1 parent 0be5dca commit f7b2176
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 12 deletions.
19 changes: 12 additions & 7 deletions controllers/scoreController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ module.exports.checkout_post = async (req: any, res: any) => {
checkoutId,
} = req.body;

const { isAdmin, isPlaywright } = res.locals.user;

try {
if (userId && scoreId) {
let score = await Score.findOne({ id: scoreId });
Expand Down Expand Up @@ -115,7 +117,7 @@ module.exports.checkout_post = async (req: any, res: any) => {
score = await score.save();
if (score) {
const user = await User.findOne({ id: userId });
if (user) {
if (user && !isPlaywright) {
// we don't expect error because we validated the user id before
await sendCheckoutConfirmationEmail(
user,
Expand Down Expand Up @@ -214,6 +216,7 @@ module.exports.checkout_post = async (req: any, res: any) => {

module.exports.checkin_post = async (req: any, res: any) => {
const { scoreId, comment } = req.body;
const { isAdmin, isPlaywright } = res.locals.user;

try {
if (scoreId && comment != undefined) {
Expand All @@ -240,16 +243,18 @@ module.exports.checkin_post = async (req: any, res: any) => {

score = await score.save();
if (score) {
await sendCheckinConfirmationEmail(
user,
score,
process.env.EMAIL_TEST_RECIPIENT
);
if (!isPlaywright) {
await sendCheckinConfirmationEmail(
user,
score,
process.env.EMAIL_TEST_RECIPIENT
);
}
res.status(201).json({ checkinScore: score });
} else {
res
.status(400)
.json({ errors: "Update score with checkout record failed" });
.json({ errors: "Update score checkout record for checkin failed" });
}
} else {
res.status(400).json({
Expand Down
10 changes: 7 additions & 3 deletions dist/controllers/scoreController.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ module.exports.checkout_get = (req, res) => {
};
module.exports.checkout_post = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const { userJwtOrCheckoutId, userId, userLastName, scoreId, scoreExtId, state, date, comment, allowDoubleCheckout, checkoutId, } = req.body;
const { isAdmin, isPlaywright } = res.locals.user;
try {
if (userId && scoreId) {
let score = yield Score_1.Score.findOne({ id: scoreId });
Expand All @@ -99,7 +100,7 @@ module.exports.checkout_post = (req, res) => __awaiter(void 0, void 0, void 0, f
score = yield score.save();
if (score) {
const user = yield User_1.User.findOne({ id: userId });
if (user) {
if (user && !isPlaywright) {
// we don't expect error because we validated the user id before
yield sendCheckoutConfirmationEmail(user, score, process.env.EMAIL_TEST_RECIPIENT);
}
Expand Down Expand Up @@ -201,6 +202,7 @@ module.exports.checkout_post = (req, res) => __awaiter(void 0, void 0, void 0, f
});
module.exports.checkin_post = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const { scoreId, comment } = req.body;
const { isAdmin, isPlaywright } = res.locals.user;
try {
if (scoreId && comment != undefined) {
// checkin request
Expand All @@ -226,13 +228,15 @@ module.exports.checkin_post = (req, res) => __awaiter(void 0, void 0, void 0, fu
checkout.checkinComment = comment;
score = yield score.save();
if (score) {
yield sendCheckinConfirmationEmail(user, score, process.env.EMAIL_TEST_RECIPIENT);
if (!isPlaywright) {
yield sendCheckinConfirmationEmail(user, score, process.env.EMAIL_TEST_RECIPIENT);
}
res.status(201).json({ checkinScore: score });
}
else {
res
.status(400)
.json({ errors: "Update score with checkout record failed" });
.json({ errors: "Update score checkout record for checkin failed" });
}
}
else {
Expand Down
4 changes: 4 additions & 0 deletions dist/models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ const userSchema = new mongoose_1.Schema({
type: Boolean,
default: false,
},
isPlaywright: {
type: Boolean,
default: false,
},
active: {
type: Boolean,
default: true,
Expand Down
5 changes: 5 additions & 0 deletions models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface IUser {
isAdmin: boolean;
isManuallyRegistered: boolean;
isPasswordHashed: boolean;
isPlaywright: boolean;
active: boolean;
}

Expand Down Expand Up @@ -109,6 +110,10 @@ const userSchema = new Schema<IUser, UserModel, IUserMethods>({
type: Boolean,
default: false,
},
isPlaywright: {
type: Boolean,
default: false,
},
active: {
type: Boolean,
default: true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"typescript": "^5.2.2"
},
"scripts": {
"start": "node dist/app.js",
"start": "ts-node app.ts",
"dev": "nodemon app.ts",
"pretty-quick": "pretty-quick"
},
Expand Down
2 changes: 1 addition & 1 deletion views/not-verified.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<h1>Benutzer nicht verifiziert</h1>

Deine E-Mail Adresse wurde noch nicht veriziert. Du kannst dir hier einen neuen Link zur Verifizierung zusenden lassen.
Deine E-Mail Adresse wurde noch nicht verifiziert. Du kannst dir hier einen neuen Link zur Verifizierung zusenden lassen.
<p>

<form action="/not-verified">
Expand Down

0 comments on commit f7b2176

Please sign in to comment.