|
| 1 | +const { validatePhoneNumber } = require("../helper/utils"); |
| 2 | + |
| 3 | +it("should return false if non number string is passed", () => { |
| 4 | + expect(validatePhoneNumber("onetwothree")).toBe(false); |
| 5 | +}); |
| 6 | + |
| 7 | +test("it returns false when a string argument is passed", () => { |
| 8 | + expect(validatePhoneNumber("onetwothree")).toBe(false); |
| 9 | +}); |
| 10 | + |
| 11 | +describe("Validate Phone Number", () => { |
| 12 | + describe("when valid phone number is passed", () => { |
| 13 | + it("should return true for a valid Bangladeshi phone number", () => { |
| 14 | + const phoneNumber = "01622971272"; |
| 15 | + expect(validatePhoneNumber(phoneNumber)).toBe(true); |
| 16 | + }); |
| 17 | + |
| 18 | + it('should return true for a valid Bangladeshi phone number wth the "+" sign', () => { |
| 19 | + const phoneNumber = "+8801622971272"; |
| 20 | + expect(validatePhoneNumber(phoneNumber)).toBe(true); |
| 21 | + }); |
| 22 | + it('should return true for a valid Bangladeshi phone number without the "+" sign', () => { |
| 23 | + const phoneNumber = "8801622971272"; |
| 24 | + expect(validatePhoneNumber(phoneNumber)).toBe(true); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should return true for a valid Bangladeshi phone number the "0088" prefix', () => { |
| 28 | + const phoneNumber = "008801622971272"; |
| 29 | + expect(validatePhoneNumber(phoneNumber)).toBe(true); |
| 30 | + }); |
| 31 | + }); |
| 32 | + |
| 33 | + describe("when invalid phone number is passed", () => { |
| 34 | + it("should return false for an invalid phone number", () => { |
| 35 | + const phoneNumber = "+8801234"; |
| 36 | + expect(validatePhoneNumber(phoneNumber)).toBe(false); |
| 37 | + }); |
| 38 | + |
| 39 | + it("should return false for a phone number with an incorrect digit", () => { |
| 40 | + const phoneNumber = "+88012345678A"; |
| 41 | + expect(validatePhoneNumber(phoneNumber)).toBe(false); |
| 42 | + }); |
| 43 | + |
| 44 | + it("should return false for a phone number with more than 11 digits", () => { |
| 45 | + const phoneNumber = "+88012345678901"; |
| 46 | + expect(validatePhoneNumber(phoneNumber)).toBe(false); |
| 47 | + }); |
| 48 | + |
| 49 | + it("should return false for a phone number with less than 11 digits", () => { |
| 50 | + const phoneNumber = "+88012345678"; |
| 51 | + expect(validatePhoneNumber(phoneNumber)).toBe(false); |
| 52 | + }); |
| 53 | + }); |
| 54 | +}); |
0 commit comments