|
1 | | -import { EmailRecipient } from "../../src/internal/model/emailRecipient"; |
2 | | -import { JunoError, JunoValidationError } from "../../src/lib/errors"; |
3 | | -import { validateEmailRecipient, validateProjectIdentifier, validateSendGridKey, validateString, validateUserIdentifier } from "../../src/lib/validators"; |
4 | | - |
5 | | -describe("Email validation tests", () => { |
6 | | - it("throws an error if a recipient is null", () => { |
| 1 | +import { EmailRecipient } from '../../src/internal/models/emailRecipient'; |
| 2 | +import { JunoError, JunoValidationError } from '../../src/lib/errors'; |
| 3 | +import { |
| 4 | + validateEmailRecipient, |
| 5 | + validateProjectIdentifier, |
| 6 | + validateSendGridKey, |
| 7 | + validateString, |
| 8 | + validateUserIdentifier, |
| 9 | +} from '../../src/lib/validators'; |
| 10 | + |
| 11 | +describe('Email validation tests', () => { |
| 12 | + it('throws an error if a recipient is null', () => { |
7 | 13 | let validEmailRecipient: unknown = null; |
8 | 14 |
|
9 | 15 | expect(() => { |
10 | 16 | validateEmailRecipient(validEmailRecipient as EmailRecipient); |
11 | 17 | }).toThrow(JunoError); |
12 | 18 | }); |
13 | 19 |
|
14 | | - it("throws an error if a recipient email is null", () => { |
| 20 | + it('throws an error if a recipient email is null', () => { |
15 | 21 | let validEmailRecipient: unknown = {}; |
16 | 22 |
|
17 | 23 | expect(() => { |
18 | 24 | validateEmailRecipient(validEmailRecipient as EmailRecipient); |
19 | 25 | }).toThrow(JunoError); |
20 | 26 |
|
21 | 27 | validEmailRecipient = { |
22 | | - email: null |
23 | | - } |
| 28 | + email: null, |
| 29 | + }; |
24 | 30 |
|
25 | 31 | expect(() => { |
26 | 32 | validateEmailRecipient(validEmailRecipient as EmailRecipient); |
27 | 33 | }).toThrow(JunoError); |
28 | 34 | }); |
29 | 35 |
|
30 | | - |
31 | | - it("throws an error if a recipient email is blank", () => { |
| 36 | + it('throws an error if a recipient email is blank', () => { |
32 | 37 | let validEmailRecipient: unknown = { |
33 | | - email: " " |
| 38 | + email: ' ', |
34 | 39 | }; |
35 | 40 |
|
36 | 41 | expect(() => { |
37 | 42 | validateEmailRecipient(validEmailRecipient as EmailRecipient); |
38 | 43 | }).toThrow(JunoError); |
39 | 44 | }); |
40 | 45 |
|
41 | | - it("does not throw an error if a recipient name is null", () => { |
| 46 | + it('does not throw an error if a recipient name is null', () => { |
42 | 47 | let validEmailRecipient: unknown = { |
43 | | - email: "someEmail" |
| 48 | + email: 'someEmail', |
44 | 49 | }; |
45 | 50 |
|
46 | 51 | validateEmailRecipient(validEmailRecipient as EmailRecipient); |
47 | 52 | }); |
48 | 53 |
|
49 | | - it("does not throw an error if a recipient name is blank", () => { |
| 54 | + it('does not throw an error if a recipient name is blank', () => { |
50 | 55 | let validEmailRecipient: unknown = { |
51 | | - email: "someEmail", |
52 | | - name: " " |
| 56 | + email: 'someEmail', |
| 57 | + name: ' ', |
53 | 58 | }; |
54 | 59 |
|
55 | 60 | validateEmailRecipient(validEmailRecipient as EmailRecipient); |
56 | 61 | }); |
57 | | - |
58 | 62 | }); |
59 | 63 |
|
60 | | - |
61 | | -describe("String validation tests", () => { |
62 | | - it("throws an error if the string is empty or null", () => { |
63 | | - let str = ""; |
| 64 | +describe('String validation tests', () => { |
| 65 | + it('throws an error if the string is empty or null', () => { |
| 66 | + let str = ''; |
64 | 67 |
|
65 | 68 | expect(() => { |
66 | | - validateString(str) |
| 69 | + validateString(str); |
67 | 70 | }).toThrow(JunoError); |
68 | 71 |
|
69 | | - |
70 | 72 | let nullStr: unknown = null; |
71 | 73 |
|
72 | 74 | expect(() => { |
73 | | - validateString(nullStr as string) |
| 75 | + validateString(nullStr as string); |
74 | 76 | }).toThrow(JunoError); |
75 | | - }) |
| 77 | + }); |
76 | 78 |
|
77 | | - it("throws an error if the string is not actually a string", () => { |
| 79 | + it('throws an error if the string is not actually a string', () => { |
78 | 80 | let fakeStr: any = 3; |
79 | 81 |
|
80 | 82 | expect(() => { |
81 | | - validateString(fakeStr) |
| 83 | + validateString(fakeStr); |
82 | 84 | }).toThrow(JunoError); |
83 | | - }) |
| 85 | + }); |
84 | 86 |
|
85 | | - it("throws an error if the string is blank", () => { |
86 | | - let str = " "; |
| 87 | + it('throws an error if the string is blank', () => { |
| 88 | + let str = ' '; |
87 | 89 |
|
88 | 90 | expect(() => { |
89 | | - validateString(str) |
| 91 | + validateString(str); |
90 | 92 | }).toThrow(JunoError); |
91 | | - }) |
| 93 | + }); |
92 | 94 | }); |
93 | 95 |
|
94 | | -describe("Validate user identifier tests", () => { |
95 | | - it("validates against null input", () => { |
| 96 | +describe('Validate user identifier tests', () => { |
| 97 | + it('validates against null input', () => { |
96 | 98 | expect(() => validateUserIdentifier(null as any)).toThrow(JunoError); |
97 | 99 | }); |
98 | 100 |
|
99 | | - it("validates against having both inputs", () => { |
100 | | - expect(() => validateUserIdentifier({ email: "a", id: 4 } as any)).toThrow(JunoError); |
| 101 | + it('validates against having both inputs', () => { |
| 102 | + expect(() => validateUserIdentifier({ email: 'a', id: 4 } as any)).toThrow( |
| 103 | + JunoError |
| 104 | + ); |
101 | 105 | }); |
102 | 106 |
|
103 | | - it("validates against negative id", () => { |
104 | | - expect(() => validateUserIdentifier({ email: "a", id: -4 } as any)).toThrow(JunoError); |
| 107 | + it('validates against negative id', () => { |
| 108 | + expect(() => validateUserIdentifier({ email: 'a', id: -4 } as any)).toThrow( |
| 109 | + JunoError |
| 110 | + ); |
105 | 111 | }); |
106 | 112 |
|
107 | | - it("validates against empty email", () => { |
108 | | - expect(() => validateUserIdentifier({ email: "" } as any)).toThrow(JunoError); |
| 113 | + it('validates against empty email', () => { |
| 114 | + expect(() => validateUserIdentifier({ email: '' } as any)).toThrow( |
| 115 | + JunoError |
| 116 | + ); |
109 | 117 | }); |
110 | 118 |
|
111 | | - it("validates against null email", () => { |
112 | | - expect(() => validateUserIdentifier({ email: null } as any)).toThrow(JunoError); |
| 119 | + it('validates against null email', () => { |
| 120 | + expect(() => validateUserIdentifier({ email: null } as any)).toThrow( |
| 121 | + JunoError |
| 122 | + ); |
113 | 123 | }); |
114 | 124 |
|
115 | | - it("validates against null id", () => { |
116 | | - expect(() => validateUserIdentifier({ id: null } as any)).toThrow(JunoError); |
| 125 | + it('validates against null id', () => { |
| 126 | + expect(() => validateUserIdentifier({ id: null } as any)).toThrow( |
| 127 | + JunoError |
| 128 | + ); |
117 | 129 | }); |
118 | 130 |
|
119 | | - it("validates against valid id", () => { |
120 | | - expect(() => validateUserIdentifier({ id: 3 } as any)).not.toThrow(JunoError); |
| 131 | + it('validates against valid id', () => { |
| 132 | + expect(() => validateUserIdentifier({ id: 3 } as any)).not.toThrow( |
| 133 | + JunoError |
| 134 | + ); |
121 | 135 | }); |
122 | 136 |
|
123 | | - it("validates against valid email", () => { |
124 | | - expect(() => validateUserIdentifier({ email: "email" })).not.toThrow(JunoError); |
| 137 | + it('validates against valid email', () => { |
| 138 | + expect(() => validateUserIdentifier({ email: 'email' })).not.toThrow( |
| 139 | + JunoError |
| 140 | + ); |
125 | 141 | expect(() => validateUserIdentifier({ id: 3 })).not.toThrow(JunoError); |
126 | 142 | }); |
127 | 143 | }); |
128 | 144 |
|
129 | | -describe("Validate project identifier tests", () => { |
130 | | - it("validates against null input", () => { |
| 145 | +describe('Validate project identifier tests', () => { |
| 146 | + it('validates against null input', () => { |
131 | 147 | expect(() => validateProjectIdentifier(null as any)).toThrow(JunoError); |
132 | 148 | }); |
133 | 149 |
|
134 | | - it("validates against having both inputs", () => { |
135 | | - expect(() => validateProjectIdentifier({ name: "a", id: 4 } as any)).toThrow(JunoError); |
| 150 | + it('validates against having both inputs', () => { |
| 151 | + expect(() => |
| 152 | + validateProjectIdentifier({ name: 'a', id: 4 } as any) |
| 153 | + ).toThrow(JunoError); |
136 | 154 | }); |
137 | 155 |
|
138 | | - it("validates against negative id", () => { |
139 | | - expect(() => validateProjectIdentifier({ name: "a", id: -4 } as any)).toThrow(JunoError); |
| 156 | + it('validates against negative id', () => { |
| 157 | + expect(() => |
| 158 | + validateProjectIdentifier({ name: 'a', id: -4 } as any) |
| 159 | + ).toThrow(JunoError); |
140 | 160 | }); |
141 | 161 |
|
142 | | - it("validates against empty name", () => { |
143 | | - expect(() => validateProjectIdentifier({ name: "" } as any)).toThrow(JunoError); |
| 162 | + it('validates against empty name', () => { |
| 163 | + expect(() => validateProjectIdentifier({ name: '' } as any)).toThrow( |
| 164 | + JunoError |
| 165 | + ); |
144 | 166 | }); |
145 | 167 |
|
146 | | - it("validates against null name", () => { |
147 | | - expect(() => validateProjectIdentifier({ name: null } as any)).toThrow(JunoError); |
| 168 | + it('validates against null name', () => { |
| 169 | + expect(() => validateProjectIdentifier({ name: null } as any)).toThrow( |
| 170 | + JunoError |
| 171 | + ); |
148 | 172 | }); |
149 | 173 |
|
150 | | - it("validates against null id", () => { |
151 | | - expect(() => validateProjectIdentifier({ id: null } as any)).toThrow(JunoError); |
| 174 | + it('validates against null id', () => { |
| 175 | + expect(() => validateProjectIdentifier({ id: null } as any)).toThrow( |
| 176 | + JunoError |
| 177 | + ); |
152 | 178 | }); |
153 | 179 |
|
154 | | - it("validates against valid id", () => { |
155 | | - expect(() => validateProjectIdentifier({ id: 3 } as any)).not.toThrow(JunoError); |
| 180 | + it('validates against valid id', () => { |
| 181 | + expect(() => validateProjectIdentifier({ id: 3 } as any)).not.toThrow( |
| 182 | + JunoError |
| 183 | + ); |
156 | 184 | }); |
157 | 185 |
|
158 | | - it("validates against valid name", () => { |
159 | | - expect(() => validateProjectIdentifier({ name: "name" })).not.toThrow(JunoError); |
| 186 | + it('validates against valid name', () => { |
| 187 | + expect(() => validateProjectIdentifier({ name: 'name' })).not.toThrow( |
| 188 | + JunoError |
| 189 | + ); |
160 | 190 | expect(() => validateProjectIdentifier({ id: 3 })).not.toThrow(JunoError); |
161 | 191 | }); |
162 | 192 | }); |
163 | 193 |
|
164 | | - |
165 | | - |
166 | | -describe("Validate sendgrid key tests", () => { |
167 | | - it("fails validation against null (missing) sendgrid key", () => { |
| 194 | +describe('Validate sendgrid key tests', () => { |
| 195 | + it('fails validation against null (missing) sendgrid key', () => { |
168 | 196 | expect(() => validateSendGridKey(null as any)).toThrow(JunoValidationError); |
169 | 197 | }); |
170 | 198 |
|
171 | | - it("fails validation against empty sendgrid key", () => { |
172 | | - expect(() => validateSendGridKey("")).toThrow(JunoValidationError); |
| 199 | + it('fails validation against empty sendgrid key', () => { |
| 200 | + expect(() => validateSendGridKey('')).toThrow(JunoValidationError); |
173 | 201 | }); |
174 | 202 |
|
175 | | - it("fails validation against providing a sendgrid key without prefix of SG", () => { |
176 | | - expect(() => validateSendGridKey("awdiojawiodj")).toThrow(JunoValidationError); |
| 203 | + it('fails validation against providing a sendgrid key without prefix of SG', () => { |
| 204 | + expect(() => validateSendGridKey('awdiojawiodj')).toThrow( |
| 205 | + JunoValidationError |
| 206 | + ); |
177 | 207 | }); |
178 | 208 |
|
179 | | - it("fails validation a sendgrid key that is non-string", () => { |
| 209 | + it('fails validation a sendgrid key that is non-string', () => { |
180 | 210 | expect(() => validateSendGridKey(3 as any)).toThrow(JunoValidationError); |
181 | 211 | }); |
182 | 212 |
|
183 | | - |
184 | | - it("validates a sendgrid key that is valid", () => { |
185 | | - expect(() => validateSendGridKey("SG.aiwjdiowa")).not.toThrow(JunoError); |
| 213 | + it('validates a sendgrid key that is valid', () => { |
| 214 | + expect(() => validateSendGridKey('SG.aiwjdiowa')).not.toThrow(JunoError); |
186 | 215 | }); |
187 | | - |
188 | | -}) |
| 216 | +}); |
0 commit comments