mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-11-24 08:13:38 +00:00
Merge "Create fake user when userinfo request fails"
This commit is contained in:
commit
374fe5560d
|
@ -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 ) );
|
||||
|
|
|
@ -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();
|
||||
} );
|
||||
} );
|
||||
|
|
Loading…
Reference in a new issue