Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const users = [
- new User({ username: 'test1', email: 'test1@test.de', password: '1234'}),
- new User({ username: 'test2', email: 'test2@test.de', password: '5678'}),
- ];
- test.cb.beforeEach('Connect and add two users', t => {
- connectDB(t, () => {
- User.create(users, (err, user) => {
- if (err) t.fail('Unable to create users');
- t.end();
- });
- });
- });
- test.serial('Should find the initially added users', async t => {
- t.plan(2);
- const firstUser = await User.findOne({ username: 'test1' }).exec();
- t.is(firstUser.username, 'test1');
- const secondUser = await User.findOne({ username: 'test2' }).exec();
- t.is(secondUser.username, 'test2');
- });
- test.serial('Should return a 200 status when user loggs in', async t => {
- t.plan(1);
- //just for debugging
- User.findOne({email: 'test1@test.de'}, function(err, user) {
- console.log(user); //returns null
- });
- //just for debugging
- User.find({}, function(err, user) {
- console.log(user); //returns []
- });
- const res = await request(app)
- .post('/api/users/authenticate')
- .send({email: 'test1@test.de', password: '1234'});
- t.is(res.status, 200);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement