From ae638893b24709032821310bd0b1d0c7cf80fdd4 Mon Sep 17 00:00:00 2001 From: Pierre Brisorgueil Date: Wed, 19 Oct 2016 17:59:45 +0200 Subject: [PATCH] fix(users): test for usernameOrEmail (#1582) --- modules/users/tests/e2e/users.e2e.tests.js | 2 +- .../tests/server/user.server.routes.tests.js | 47 ++++++++++++++----- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/modules/users/tests/e2e/users.e2e.tests.js b/modules/users/tests/e2e/users.e2e.tests.js index a6584bb8f3..6c232bfa4f 100644 --- a/modules/users/tests/e2e/users.e2e.tests.js +++ b/modules/users/tests/e2e/users.e2e.tests.js @@ -113,7 +113,7 @@ describe('Users E2E Tests:', function () { expect(element.all(by.css('.error-text')).get(0).getText()).toBe('Email address is invalid.'); }); - it('Should report missing username or email', function () { + it('Should report missing username', function () { browser.get('http://localhost:3001/authentication/signup'); // Enter First Name element(by.model('vm.credentials.firstName')).sendKeys(user1.firstName); diff --git a/modules/users/tests/server/user.server.routes.tests.js b/modules/users/tests/server/user.server.routes.tests.js index 9288a53488..648dd8cc9b 100644 --- a/modules/users/tests/server/user.server.routes.tests.js +++ b/modules/users/tests/server/user.server.routes.tests.js @@ -90,7 +90,7 @@ describe('User CRUD tests', function () { }); }); - it('should be able to login with username and email successfully and logout successfully', function (done) { + it('should be able to login with username successfully and logout successfully', function (done) { // Login with username agent.post('/api/auth/signin') .send(credentials) @@ -119,18 +119,41 @@ describe('User CRUD tests', function () { signoutRes.text.should.equal('Moved Temporarily. Redirecting to /'); } - // Login with username - agent.post('/api/auth/signin') - .send(credentials) - .expect(200) - .end(function (signinErr, signinRes) { - // Handle signin error - if (signinErr) { - return done(signinErr); - } + return done(); + }); + }); + }); - return done(); - }); + it('should be able to login with email successfully and logout successfully', function (done) { + // Login with username + agent.post('/api/auth/signin') + .send(credentialsEmail) + .expect(200) + .end(function (signinErr, signinRes) { + // Handle signin error + if (signinErr) { + return done(signinErr); + } + + // Logout + agent.get('/api/auth/signout') + .expect(302) + .end(function (signoutErr, signoutRes) { + if (signoutErr) { + return done(signoutErr); + } + + signoutRes.redirect.should.equal(true); + + // NodeJS v4 changed the status code representation so we must check + // before asserting, to be comptabile with all node versions. + if (semver.satisfies(process.versions.node, '>=4.0.0')) { + signoutRes.text.should.equal('Found. Redirecting to /'); + } else { + signoutRes.text.should.equal('Moved Temporarily. Redirecting to /'); + } + + return done(); }); }); });