Skip to content

Commit f2a949e

Browse files
authored
Merge pull request #2230 from Real-Dev-Squad/develop
Dev to Main Sync
2 parents df1040c + 32b8c95 commit f2a949e

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

controllers/subscription.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ const emailServiceConfig = config.get("emailServiceConfig");
77

88
export const subscribe = async (req: CustomRequest, res: CustomResponse) => {
99
const { email } = req.body;
10-
const phoneNumber = req.body.phoneNumber || null;
10+
const phone = req.body.phone || null;
1111
const userId = req.userData.id;
12-
const data = { email, isSubscribed: true, phoneNumber };
12+
const data = { email, isSubscribed: true, phone };
1313
const userAlreadySubscribed = req.userData.isSubscribed;
1414
try {
1515
if (userAlreadySubscribed) {
@@ -71,4 +71,4 @@ export const sendEmail = async (req: CustomRequest, res: CustomResponse) => {
7171
logger.error("Error occurred while sending email:", error.message);
7272
return res.boom.badImplementation(INTERNAL_SERVER_ERROR);
7373
}
74-
};
74+
};

middlewares/validators/subscription.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ export const validateSubscribe = (req: CustomRequest, res: CustomResponse, next:
88
if(req.body.email){
99
req.body.email = req.body.email.trim();
1010
}
11-
if (req.body.phoneNumber) {
12-
req.body.phoneNumber = req.body.phoneNumber.trim();
11+
if (req.body.phone) {
12+
req.body.phone = req.body.phone.trim();
1313
}
1414
const subscribeSchema = Joi.object({
15-
phoneNumber: Joi.string().allow('').optional().regex(phoneNumberRegex),
15+
phone: Joi.string().allow('').optional().regex(phoneNumberRegex),
1616
email: Joi.string().required().regex(emailRegex)
1717
});
1818
const { error } = subscribeSchema.validate(req.body);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export const subscribedMessage = "User subscribed successfully";
22
export const unSubscribedMessage = "User unsubscribed successfully";
33
export const subscriptionData = {
4-
phoneNumber: "+911234567890",
4+
phone: "+911234567890",
55
66
};
77

test/unit/middlewares/subscription-validator.test.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe("Middleware | Validators | Subscription", function () {
1616

1717
it("should call next function when a valid request body is passed", async function () {
1818
req.body = {
19-
phoneNumber: "+911234567890",
19+
phone: "+911234567890",
2020
2121
};
2222

@@ -27,7 +27,7 @@ describe("Middleware | Validators | Subscription", function () {
2727
expect(res.json.called).to.be.equal(false);
2828
});
2929

30-
it("should not return an error when phoneNumber is missing", async function () {
30+
it("should not return an error when phone is missing", async function () {
3131
req.body = {
3232
3333
};
@@ -40,7 +40,7 @@ describe("Middleware | Validators | Subscription", function () {
4040

4141
it("should return a 400 error when email is missing", async function () {
4242
req.body = {
43-
phoneNumber: "+911234567890",
43+
phone: "+911234567890",
4444
};
4545

4646
validateSubscribe(req, res, nextSpy);
@@ -51,7 +51,7 @@ describe("Middleware | Validators | Subscription", function () {
5151
expect(res.json.firstCall.args[0]).to.have.property("error").that.includes('"email" is required');
5252
});
5353

54-
it("should return a 400 error when both phoneNumber and email are missing", async function () {
54+
it("should return a 400 error when both phone and email are missing", async function () {
5555
req.body = {};
5656

5757
validateSubscribe(req, res, nextSpy);
@@ -63,7 +63,7 @@ describe("Middleware | Validators | Subscription", function () {
6363

6464
it("should return a 400 error when email is not in correct format", async function () {
6565
req.body = {
66-
phoneNumber: "+911234567890",
66+
phone: "+911234567890",
6767
email: "invalid-email",
6868
};
6969

@@ -77,9 +77,9 @@ describe("Middleware | Validators | Subscription", function () {
7777
.that.includes('"email" with value "invalid-email" fails to match the required pattern');
7878
});
7979

80-
it("should not return an error when phoneNumber is in correct format", async function () {
80+
it("should not return an error when phone is in correct format", async function () {
8181
req.body = {
82-
phoneNumber: "+911234567890",
82+
phone: "+911234567890",
8383
8484
};
8585

@@ -89,9 +89,9 @@ describe("Middleware | Validators | Subscription", function () {
8989
expect(res.json.called).to.be.equal(false);
9090
});
9191

92-
it("should trim and validate phoneNumber if it contains leading or trailing spaces", async function () {
92+
it("should trim and validate phone if it contains leading or trailing spaces", async function () {
9393
req.body = {
94-
phoneNumber: " +911234567890 ",
94+
phone: " +911234567890 ",
9595
9696
};
9797

@@ -100,12 +100,12 @@ describe("Middleware | Validators | Subscription", function () {
100100
expect(nextSpy.calledOnce).to.be.equal(true);
101101
expect(res.status.called).to.be.equal(false);
102102
expect(res.json.called).to.be.equal(false);
103-
expect(req.body.phoneNumber).to.equal("+911234567890");
103+
expect(req.body.phone).to.equal("+911234567890");
104104
});
105105

106-
it("should return a 400 error when phoneNumber is in incorrect format", async function () {
106+
it("should return a 400 error when phone is in incorrect format", async function () {
107107
req.body = {
108-
phoneNumber: "invalid-number",
108+
phone: "invalid-number",
109109
110110
};
111111

@@ -116,6 +116,6 @@ describe("Middleware | Validators | Subscription", function () {
116116
expect(res.json.calledOnce).to.be.equal(true);
117117
expect(res.json.firstCall.args[0])
118118
.to.have.property("error")
119-
.that.includes('"phoneNumber" with value "invalid-number" fails to match the required pattern');
119+
.that.includes('"phone" with value "invalid-number" fails to match the required pattern');
120120
});
121121
});

types/global.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export type userData = {
3737
username: string;
3838
updated_at: number;
3939
isSubscribed: boolean;
40-
phoneNumber: string | null;
40+
phone: string | null;
4141
email: string;
4242
};
4343

0 commit comments

Comments
 (0)