Advertisement
Guest User

Untitled

a guest
Feb 1st, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. const users = [
  2. new User({ username: 'test1', email: 'test1@test.de', password: '1234'}),
  3. new User({ username: 'test2', email: 'test2@test.de', password: '5678'}),
  4. ];
  5.  
  6. test.cb.beforeEach('Connect and add two users', t => {
  7. connectDB(t, () => {
  8. User.create(users, (err, user) => {
  9. if (err) t.fail('Unable to create users');
  10. t.end();
  11. });
  12. });
  13. });
  14.  
  15. test.serial('Should find the initially added users', async t => {
  16. t.plan(2);
  17.  
  18. const firstUser = await User.findOne({ username: 'test1' }).exec();
  19. t.is(firstUser.username, 'test1');
  20.  
  21. const secondUser = await User.findOne({ username: 'test2' }).exec();
  22. t.is(secondUser.username, 'test2');
  23. });
  24.  
  25. test.serial('Should return a 200 status when user loggs in', async t => {
  26. t.plan(1);
  27.  
  28. //just for debugging
  29. User.findOne({email: 'test1@test.de'}, function(err, user) {
  30. console.log(user); //returns null
  31. });
  32.  
  33. //just for debugging
  34. User.find({}, function(err, user) {
  35. console.log(user); //returns []
  36. });
  37.  
  38. const res = await request(app)
  39. .post('/api/users/authenticate')
  40. .send({email: 'test1@test.de', password: '1234'});
  41. t.is(res.status, 200);
  42. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement