generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
49 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; | ||
export const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; | ||
export const phoneNumberRegex = /^[+]{1}(?:[0-9\-\\(\\)\\/.]\s?){6,15}[0-9]{1}$/; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ describe("Middleware | Validators | Subscription", function () { | |
email: "[email protected]", | ||
}; | ||
|
||
await validateSubscribe(req, res, nextSpy); | ||
validateSubscribe(req, res, nextSpy); | ||
|
||
expect(nextSpy.calledOnce).to.be.equal(true); | ||
expect(res.status.called).to.be.equal(false); | ||
|
@@ -32,7 +32,7 @@ describe("Middleware | Validators | Subscription", function () { | |
email: "[email protected]", | ||
}; | ||
|
||
await validateSubscribe(req, res, nextSpy); | ||
validateSubscribe(req, res, nextSpy); | ||
expect(nextSpy.calledOnce).to.be.equal(true); | ||
expect(res.status.called).to.be.equal(false); | ||
expect(res.json.called).to.be.equal(false); | ||
|
@@ -43,7 +43,7 @@ describe("Middleware | Validators | Subscription", function () { | |
phoneNumber: "+911234567890", | ||
}; | ||
|
||
await validateSubscribe(req, res, nextSpy); | ||
validateSubscribe(req, res, nextSpy); | ||
|
||
expect(nextSpy.called).to.be.equal(false); | ||
expect(res.status.calledOnceWith(400)).to.be.equal(true); | ||
|
@@ -54,7 +54,7 @@ describe("Middleware | Validators | Subscription", function () { | |
it("should return a 400 error when both phoneNumber and email are missing", async function () { | ||
req.body = {}; | ||
|
||
await validateSubscribe(req, res, nextSpy); | ||
validateSubscribe(req, res, nextSpy); | ||
expect(nextSpy.called).to.be.equal(false); | ||
expect(res.status.calledOnceWith(400)).to.be.equal(true); | ||
expect(res.json.calledOnce).to.be.equal(true); | ||
|
@@ -67,7 +67,7 @@ describe("Middleware | Validators | Subscription", function () { | |
email: "invalid-email", | ||
}; | ||
|
||
await validateSubscribe(req, res, nextSpy); | ||
validateSubscribe(req, res, nextSpy); | ||
|
||
expect(nextSpy.called).to.be.equal(false); | ||
expect(res.status.calledOnceWith(400)).to.be.equal(true); | ||
|
@@ -83,9 +83,39 @@ describe("Middleware | Validators | Subscription", function () { | |
email: "[email protected]", | ||
}; | ||
|
||
await validateSubscribe(req, res, nextSpy); | ||
validateSubscribe(req, res, nextSpy); | ||
expect(nextSpy.calledOnce).to.be.equal(true); | ||
expect(res.status.called).to.be.equal(false); | ||
expect(res.json.called).to.be.equal(false); | ||
}); | ||
|
||
it("should trim and validate phoneNumber if it contains leading or trailing spaces", async function () { | ||
req.body = { | ||
phoneNumber: " +911234567890 ", | ||
email: "[email protected]", | ||
}; | ||
|
||
validateSubscribe(req, res, nextSpy); | ||
|
||
expect(nextSpy.calledOnce).to.be.equal(true); | ||
expect(res.status.called).to.be.equal(false); | ||
expect(res.json.called).to.be.equal(false); | ||
expect(req.body.phoneNumber).to.equal("+911234567890"); | ||
}); | ||
|
||
it("should return a 400 error when phoneNumber is in incorrect format", async function () { | ||
req.body = { | ||
phoneNumber: "invalid-number", | ||
email: "[email protected]", | ||
}; | ||
|
||
validateSubscribe(req, res, nextSpy); | ||
|
||
expect(nextSpy.called).to.be.equal(false); | ||
expect(res.status.calledOnceWith(400)).to.be.equal(true); | ||
expect(res.json.calledOnce).to.be.equal(true); | ||
expect(res.json.firstCall.args[0]) | ||
.to.have.property("error") | ||
.that.includes('"phoneNumber" with value "invalid-number" fails to match the required pattern'); | ||
}); | ||
}); |