Merge "Create fake user when userinfo request fails"

This commit is contained in:
jenkins-bot 2014-02-28 08:48:25 +00:00 committed by Gerrit Code Review
commit 374fe5560d
2 changed files with 37 additions and 9 deletions

View file

@ -15,7 +15,7 @@
* along with MultimediaViewer. If not, see <http://www.gnu.org/licenses/>.
*/
( function ( mw, oo, $ ) {
( function ( mw, oo ) {
/**
* Gets user information (currently just the gender).
@ -65,7 +65,8 @@
if ( users[0] && users[0].name && users[0].gender ) {
return new mw.mmv.model.User( users[0].name, users[0].gender );
} else {
return $.Deferred().reject( 'error in provider, user info not found' );
mw.log( 'user info not found for ' + username + ' at ' + repoInfo.name);
return new mw.mmv.model.User( username, mw.mmv.model.User.Gender.UNKNOWN );
}
} );
}
@ -74,4 +75,4 @@
};
mw.mmv.provider.UserInfo = UserInfo;
}( mediaWiki, OO, jQuery ) );
}( mediaWiki, OO ) );

View file

@ -81,7 +81,7 @@
} );
} );
QUnit.asyncTest( 'UserInfo missing user test', 1, function ( assert ) {
QUnit.asyncTest( 'UserInfo missing user test', 2, function ( assert ) {
var api = { get: function() {
return $.Deferred().resolve( {
query: {
@ -93,13 +93,14 @@
repoInfo = {},
userInfoProvider = new mw.mmv.provider.UserInfo( api );
userInfoProvider.get( username, repoInfo ).fail( function() {
assert.ok( true, 'promise rejected when user is missing' );
userInfoProvider.get( username, repoInfo ).done( function( user ) {
assert.strictEqual( user.username, 'Catrope', 'username is set correctly' );
assert.strictEqual( user.gender, mw.mmv.model.User.Gender.UNKNOWN, 'gender is set to unknown' );
QUnit.start();
} );
} );
QUnit.asyncTest( 'UserInfo missing gender test', 1, function ( assert ) {
QUnit.asyncTest( 'UserInfo missing gender test', 2, function ( assert ) {
var api = { get: function() {
return $.Deferred().resolve( {
query: {
@ -116,8 +117,34 @@
repoInfo = {},
userInfoProvider = new mw.mmv.provider.UserInfo( api );
userInfoProvider.get( username, repoInfo ).fail( function() {
assert.ok( true, 'promise rejected when gender is missing' );
userInfoProvider.get( username, repoInfo ).done( function( user ) {
assert.strictEqual( user.username, 'Catrope', 'username is set correctly' );
assert.strictEqual( user.gender, mw.mmv.model.User.Gender.UNKNOWN, 'gender is set to unknown' );
QUnit.start();
} );
} );
// this can happen when we get the image from a ForeignDBRepo
QUnit.asyncTest( 'UserInfo non-existant user test', 2, function ( assert ) {
var api = { get: function() {
return $.Deferred().resolve( {
query: {
users: [
{
missing: '',
name: 'Catrope'
}
]
}
} );
} },
username = 'Catrope',
repoInfo = {},
userInfoProvider = new mw.mmv.provider.UserInfo( api );
userInfoProvider.get( username, repoInfo ).done( function( user ) {
assert.strictEqual( user.username, 'Catrope', 'username is set correctly' );
assert.strictEqual( user.gender, mw.mmv.model.User.Gender.UNKNOWN, 'gender is set to unknown' );
QUnit.start();
} );
} );