Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
fix(avatars): redirect unverified users to confirm screen
Browse files Browse the repository at this point in the history
Fixes #1662.
  • Loading branch information
zaach committed Oct 1, 2014
1 parent 81a1786 commit d440e4d
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 4 deletions.
15 changes: 14 additions & 1 deletion app/scripts/views/settings/avatar.js
Expand Up @@ -8,9 +8,10 @@ define([
'underscore',
'views/form',
'stache!templates/settings/avatar',
'lib/auth-errors',
'lib/session'
],
function (_, FormView, Template, Session) {
function (_, FormView, Template, AuthErrors, Session) {
var View = FormView.extend({
// user must be authenticated to see Settings
mustAuth: true,
Expand All @@ -34,12 +35,24 @@ function (_, FormView, Template, Session) {
// we would fetch the image right after sign in, or only for
// specific email domains (#1567).
_fetchProfileImage: function () {
var self = this;

return this.profileClient.getAvatar()
.then(function (result) {
if (result.avatar) {
Session.set('avatar', result.avatar);
Session.set('avatarId', result.id);
}
}, function (err) {
if (AuthErrors.is(err, 'UNVERIFIED_ACCOUNT')) {
return self.fxaClient.signUpResend()
.then(function () {
self.navigate('confirm');
return false;
});
}

throw err;
});
}

Expand Down
30 changes: 27 additions & 3 deletions app/tests/spec/views/settings/avatar.js
Expand Up @@ -13,11 +13,14 @@ define([
'views/settings/avatar',
'../../../mocks/router',
'../../../mocks/profile',
'../../../mocks/fxa-client',
'lib/promise',
'lib/session',
'lib/profile'
'lib/profile',
'lib/auth-errors'
],
function (chai, _, $, sinon, View, RouterMock, ProfileMock, p, Session, Profile) {
function (chai, _, $, sinon, View, RouterMock, ProfileMock, FxaClientMock,
p, Session, Profile, AuthErrors) {
var assert = chai.assert;
var pngSrc = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVQYV2P4DwABAQEAWk1v8QAAAABJRU5ErkJggg==';
var IMG_URL = 'http://127.0.0.1:1112/avatar/example.jpg';
Expand All @@ -26,14 +29,17 @@ function (chai, _, $, sinon, View, RouterMock, ProfileMock, p, Session, Profile)
var view;
var routerMock;
var profileClientMock;
var fxaClientMock;

beforeEach(function () {
routerMock = new RouterMock();
profileClientMock = new ProfileMock();
fxaClientMock = new FxaClientMock();

view = new View({
router: routerMock,
profileClient: profileClientMock
profileClient: profileClientMock,
fxaClient: fxaClientMock
});
});

Expand All @@ -43,6 +49,7 @@ function (chai, _, $, sinon, View, RouterMock, ProfileMock, p, Session, Profile)
view = null;
routerMock = null;
profileClientMock = null;
fxaClientMock = null;
});

describe('with no session', function () {
Expand Down Expand Up @@ -88,6 +95,23 @@ function (chai, _, $, sinon, View, RouterMock, ProfileMock, p, Session, Profile)
});
});

it('has an unverified account', function () {
Session.clear('avatar');

sinon.stub(fxaClientMock, 'signUpResend', function () {
return p();
});

sinon.stub(profileClientMock, 'getAvatar', function () {
return p.reject(AuthErrors.toError('UNVERIFIED_ACCOUNT'));
});

return view.render()
.then(function () {
assert.equal(routerMock.page, 'confirm');
});
});

it('loads an avatar from the server', function () {
Session.clear('avatar');
var id = 'foo';
Expand Down
37 changes: 37 additions & 0 deletions tests/functional/avatar.js
Expand Up @@ -25,12 +25,14 @@ define([
var PASSWORD = 'password';
var email;
var client;
var email2;

registerSuite({
name: 'settings/avatar',

beforeEach: function () {
email = TestHelpers.createEmail();
email2 = TestHelpers.createEmail();

client = new FxaClient(AUTH_SERVER_ROOT, {
xhr: nodeXMLHttpRequest.XMLHttpRequest
Expand Down Expand Up @@ -70,6 +72,41 @@ define([
return FunctionalHelpers.clearBrowserState(this);
},

'go to avatars with unverified account': function () {
var self = this;

return client.signUp(email2, PASSWORD)
.then(function () {
return FunctionalHelpers.clearBrowserState(self);
})
.then(function () {
return self.get('remote')
.get(require.toUrl(SIGNIN_URL))
.findByCssSelector('form input.email')
.click()
.type(email2)
.end()

.findByCssSelector('form input.password')
.click()
.type(PASSWORD)
.end()

.findByCssSelector('button[type="submit"]')
.click()
.end()

.findById('fxa-confirm-header')
.end()

.get(require.toUrl(AVATAR_URL))

// success is going to the confirm page
.findById('fxa-confirm-header')
.end();
});
},

'go to avatars then avatar change': function () {
return this.get('remote')
.get(require.toUrl(AVATAR_URL))
Expand Down

0 comments on commit d440e4d

Please sign in to comment.