Skip to content
This repository was archived by the owner on Aug 30, 2021. It is now read-only.

Commit 89050d5

Browse files
committed
Adding suite of tests for the e-mail validation field in the users model
1 parent 820355c commit 89050d5

File tree

1 file changed

+255
-0
lines changed

1 file changed

+255
-0
lines changed

modules/users/tests/server/user.server.model.tests.js

Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,261 @@ describe('User Model Unit Tests:', function () {
155155

156156
});
157157

158+
describe("User E-mail Validation Tests", function() {
159+
it('should not allow invalid email address - "123"', function (done) {
160+
var _user = new User(user);
161+
162+
_user.email = '123';
163+
_user.save(function (err) {
164+
if (!err) {
165+
_user.remove(function (err_remove) {
166+
should.not.exist(err_remove);
167+
done();
168+
});
169+
} else {
170+
should.exist(err);
171+
done();
172+
}
173+
});
174+
175+
});
176+
177+
it('should not allow invalid email address - "123@123"', function (done) {
178+
var _user = new User(user);
179+
180+
_user.email = '123@123';
181+
_user.save(function (err) {
182+
if (!err) {
183+
_user.remove(function (err_remove) {
184+
should.not.exist(err_remove);
185+
done();
186+
});
187+
} else {
188+
should.exist(err);
189+
done();
190+
}
191+
});
192+
193+
});
194+
195+
it('should not allow invalid email address - "123.com"', function (done) {
196+
var _user = new User(user);
197+
198+
_user.email = '123.com';
199+
_user.save(function (err) {
200+
if (!err) {
201+
_user.remove(function (err_remove) {
202+
should.not.exist(err_remove);
203+
done();
204+
});
205+
} else {
206+
should.exist(err);
207+
done();
208+
}
209+
});
210+
211+
});
212+
213+
it('should not allow invalid email address - "@123.com"', function (done) {
214+
var _user = new User(user);
215+
216+
_user.email = '@123.com';
217+
_user.save(function (err) {
218+
if (!err) {
219+
_user.remove(function (err_remove) {
220+
should.not.exist(err_remove);
221+
done();
222+
});
223+
} else {
224+
should.exist(err);
225+
done();
226+
}
227+
});
228+
229+
});
230+
231+
it('should not allow invalid email address - "abc@[email protected]"', function (done) {
232+
var _user = new User(user);
233+
234+
_user.email = 'abc@[email protected]';
235+
_user.save(function (err) {
236+
if (!err) {
237+
_user.remove(function (err_remove) {
238+
should.not.exist(err_remove);
239+
done();
240+
});
241+
} else {
242+
should.exist(err);
243+
done();
244+
}
245+
});
246+
247+
});
248+
249+
it('should not allow invalid characters in email address - "abc~@#$%^&*()[email protected]"', function (done) {
250+
var _user = new User(user);
251+
252+
_user.email = 'abc~@#$%^&*()[email protected]';
253+
_user.save(function (err) {
254+
if (!err) {
255+
_user.remove(function (err_remove) {
256+
should.not.exist(err_remove);
257+
done();
258+
});
259+
} else {
260+
should.exist(err);
261+
done();
262+
}
263+
});
264+
265+
});
266+
267+
it('should not allow space characters in email address - "abc [email protected]"', function (done) {
268+
var _user = new User(user);
269+
270+
_user.email = 'abc [email protected]';
271+
_user.save(function (err) {
272+
if (!err) {
273+
_user.remove(function (err_remove) {
274+
should.not.exist(err_remove);
275+
done();
276+
});
277+
} else {
278+
should.exist(err);
279+
done();
280+
}
281+
});
282+
283+
});
284+
285+
it('should not allow single quote characters in email address - "abc\'[email protected]"', function (done) {
286+
var _user = new User(user);
287+
288+
_user.email = 'abc\'[email protected]';
289+
_user.save(function (err) {
290+
if (!err) {
291+
_user.remove(function (err_remove) {
292+
should.not.exist(err_remove);
293+
done();
294+
});
295+
} else {
296+
should.exist(err);
297+
done();
298+
}
299+
});
300+
301+
});
302+
303+
it('should not allow doudble quote characters in email address - "abc\"[email protected]"', function (done) {
304+
var _user = new User(user);
305+
306+
_user.email = 'abc\"[email protected]';
307+
_user.save(function (err) {
308+
if (!err) {
309+
_user.remove(function (err_remove) {
310+
should.not.exist(err_remove);
311+
done();
312+
});
313+
} else {
314+
should.exist(err);
315+
done();
316+
}
317+
});
318+
319+
});
320+
321+
it('should not allow double dotted characters in email address - "[email protected]"', function (done) {
322+
var _user = new User(user);
323+
324+
_user.email = '[email protected]';
325+
_user.save(function (err) {
326+
if (!err) {
327+
_user.remove(function (err_remove) {
328+
should.not.exist(err_remove);
329+
done();
330+
});
331+
} else {
332+
should.exist(err);
333+
done();
334+
}
335+
});
336+
337+
});
338+
339+
it('should allow valid email address - "[email protected]"', function (done) {
340+
var _user = new User(user);
341+
342+
_user.email = '[email protected]';
343+
_user.save(function (err) {
344+
if (!err) {
345+
_user.remove(function (err_remove) {
346+
should.not.exist(err_remove);
347+
done();
348+
});
349+
} else {
350+
should.exist(err);
351+
done();
352+
}
353+
});
354+
355+
});
356+
357+
it('should allow valid email address - "[email protected]"', function (done) {
358+
var _user = new User(user);
359+
360+
_user.email = '[email protected]';
361+
_user.save(function (err) {
362+
if (!err) {
363+
_user.remove(function (err_remove) {
364+
should.not.exist(err_remove);
365+
done();
366+
});
367+
} else {
368+
should.exist(err);
369+
done();
370+
}
371+
});
372+
373+
});
374+
375+
it('should allow valid email address - "[email protected]"', function (done) {
376+
var _user = new User(user);
377+
378+
_user.email = '[email protected]';
379+
_user.save(function (err) {
380+
if (!err) {
381+
_user.remove(function (err_remove) {
382+
should.not.exist(err_remove);
383+
done();
384+
});
385+
} else {
386+
should.exist(err);
387+
done();
388+
}
389+
});
390+
391+
});
392+
393+
it('should allow valid email address - "[email protected]"', function (done) {
394+
var _user = new User(user);
395+
396+
_user.email = '[email protected]';
397+
_user.save(function (err) {
398+
if (!err) {
399+
_user.remove(function (err_remove) {
400+
should.not.exist(err_remove);
401+
done();
402+
});
403+
} else {
404+
should.exist(err);
405+
done();
406+
}
407+
});
408+
409+
});
410+
411+
});
412+
158413
after(function (done) {
159414
User.remove().exec(done);
160415
});

0 commit comments

Comments
 (0)