|
| 1 | +import "./phone-number" for PhoneNumber |
| 2 | +import "wren-testie/testie" for Testie, Expect |
| 3 | + |
| 4 | +Testie.test("PhoneNumber") { |do, skip| |
| 5 | + do.test("cleans the number") { |
| 6 | + var actual = PhoneNumber.clean("(223) 456-7890") |
| 7 | + var expected = "2234567890" |
| 8 | + Expect.value(actual).toEqual(expected) |
| 9 | + } |
| 10 | + |
| 11 | + skip.test("cleans numbers with dots") { |
| 12 | + var actual = PhoneNumber.clean("223.456.7890") |
| 13 | + var expected = "2234567890" |
| 14 | + Expect.value(actual).toEqual(expected) |
| 15 | + } |
| 16 | + |
| 17 | + skip.test("cleans numbers with multiple spaces") { |
| 18 | + var actual = PhoneNumber.clean("223 456 7890 ") |
| 19 | + var expected = "2234567890" |
| 20 | + Expect.value(actual).toEqual(expected) |
| 21 | + } |
| 22 | + |
| 23 | + skip.test("invalid when 9 digits") { |
| 24 | + Expect.that { |
| 25 | + PhoneNumber.clean("123456789") |
| 26 | + }.abortsWith("must not be fewer than 10 digits") |
| 27 | + } |
| 28 | + |
| 29 | + skip.test("invalid when 11 digits does not start with a 1") { |
| 30 | + Expect.that { |
| 31 | + PhoneNumber.clean("22234567890") |
| 32 | + }.abortsWith("11 digits must start with 1") |
| 33 | + } |
| 34 | + |
| 35 | + skip.test("valid when 11 digits and starting with 1") { |
| 36 | + var actual = PhoneNumber.clean("12234567890") |
| 37 | + var expected = "2234567890" |
| 38 | + Expect.value(actual).toEqual(expected) |
| 39 | + } |
| 40 | + |
| 41 | + skip.test("valid when 11 digits and starting with 1 even with punctuation") { |
| 42 | + var actual = PhoneNumber.clean("+1 (223) 456-7890") |
| 43 | + var expected = "2234567890" |
| 44 | + Expect.value(actual).toEqual(expected) |
| 45 | + } |
| 46 | + |
| 47 | + skip.test("invalid when more than 11 digits") { |
| 48 | + Expect.that { |
| 49 | + PhoneNumber.clean("321234567890") |
| 50 | + }.abortsWith("must not be greater than 11 digits") |
| 51 | + } |
| 52 | + |
| 53 | + skip.test("invalid with letters") { |
| 54 | + Expect.that { |
| 55 | + PhoneNumber.clean("523-abc-7890") |
| 56 | + }.abortsWith("letters not permitted") |
| 57 | + } |
| 58 | + |
| 59 | + skip.test("invalid with punctuations") { |
| 60 | + Expect.that { |
| 61 | + PhoneNumber.clean("523-@:!-7890") |
| 62 | + }.abortsWith("punctuations not permitted") |
| 63 | + } |
| 64 | + |
| 65 | + skip.test("invalid if area code starts with 0") { |
| 66 | + Expect.that { |
| 67 | + PhoneNumber.clean("(023) 456-7890") |
| 68 | + }.abortsWith("area code cannot start with zero") |
| 69 | + } |
| 70 | + |
| 71 | + skip.test("invalid if area code starts with 1") { |
| 72 | + Expect.that { |
| 73 | + PhoneNumber.clean("(123) 456-7890") |
| 74 | + }.abortsWith("area code cannot start with one") |
| 75 | + } |
| 76 | + |
| 77 | + skip.test("invalid if exchange code starts with 0") { |
| 78 | + Expect.that { |
| 79 | + PhoneNumber.clean("(223) 056-7890") |
| 80 | + }.abortsWith("exchange code cannot start with zero") |
| 81 | + } |
| 82 | + |
| 83 | + skip.test("invalid if exchange code starts with 1") { |
| 84 | + Expect.that { |
| 85 | + PhoneNumber.clean("(223) 156-7890") |
| 86 | + }.abortsWith("exchange code cannot start with one") |
| 87 | + } |
| 88 | + |
| 89 | + skip.test("invalid if area code starts with 0 on valid 11-digit number") { |
| 90 | + Expect.that { |
| 91 | + PhoneNumber.clean("1 (023) 456-7890") |
| 92 | + }.abortsWith("area code cannot start with zero") |
| 93 | + } |
| 94 | + |
| 95 | + skip.test("invalid if area code starts with 1 on valid 11-digit number") { |
| 96 | + Expect.that { |
| 97 | + PhoneNumber.clean("1 (123) 456-7890") |
| 98 | + }.abortsWith("area code cannot start with one") |
| 99 | + } |
| 100 | + |
| 101 | + skip.test("invalid if exchange code starts with 0 on valid 11-digit number") { |
| 102 | + Expect.that { |
| 103 | + PhoneNumber.clean("1 (223) 056-7890") |
| 104 | + }.abortsWith("exchange code cannot start with zero") |
| 105 | + } |
| 106 | + |
| 107 | + skip.test("invalid if exchange code starts with 1 on valid 11-digit number") { |
| 108 | + Expect.that { |
| 109 | + PhoneNumber.clean("1 (223) 156-7890") |
| 110 | + }.abortsWith("exchange code cannot start with one") |
| 111 | + } |
| 112 | +} |
0 commit comments