mediawiki.user: Improve test suite
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 29 Mar 2019 20:09:32 +0000 (20:09 +0000)
committerTimo Tijhof <krinklemail@gmail.com>
Fri, 29 Mar 2019 20:12:37 +0000 (20:12 +0000)
* Add missing test for getRights with Promise.

* Separate the 'callback' and 'Promise' test cases.

Change-Id: Ia332f05e117512f32f71ff2e22bd76f8f1ee101c

tests/qunit/suites/resources/mediawiki/mediawiki.user.test.js

index 1e35211..2487672 100644 (file)
@@ -2,6 +2,7 @@
        QUnit.module( 'mediawiki.user', QUnit.newMwEnvironment( {
                setup: function () {
                        this.server = this.sandbox.useFakeServer();
+                       this.server.respondImmediately = true;
                        // Cannot stub by simple assignment because read-only.
                        // Instead, stub in tests by using 'delete', and re-create
                        // in teardown using the original descriptor (including its
                assert.strictEqual( mw.user.id(), 'John', 'user.id()' );
        } );
 
-       QUnit.test( 'getUserInfo', function ( assert ) {
+       QUnit.test( 'getGroups (callback)', function ( assert ) {
+               var done = assert.async();
                mw.config.set( 'wgUserGroups', [ '*', 'user' ] );
 
                mw.user.getGroups( function ( groups ) {
                        assert.deepEqual( groups, [ '*', 'user' ], 'Result' );
+                       done();
                } );
+       } );
+
+       QUnit.test( 'getGroups (Promise)', function ( assert ) {
+               mw.config.set( 'wgUserGroups', [ '*', 'user' ] );
+
+               return mw.user.getGroups().then( function ( groups ) {
+                       assert.deepEqual( groups, [ '*', 'user' ], 'Result' );
+               } );
+       } );
+
+       QUnit.test( 'getRights (callback)', function ( assert ) {
+               var done = assert.async();
+
+               this.server.respond( [ 200, { 'Content-Type': 'application/json' },
+                       '{ "query": { "userinfo": { "groups": [ "unused" ], "rights": [ "read", "edit", "createtalk" ] } } }'
+               ] );
 
                mw.user.getRights( function ( rights ) {
                        assert.deepEqual( rights, [ 'read', 'edit', 'createtalk' ], 'Result (callback)' );
+                       done();
                } );
+       } );
 
-               mw.user.getRights().done( function ( rights ) {
-                       assert.deepEqual( rights, [ 'read', 'edit', 'createtalk' ], 'Result (promise)' );
-               } );
+       QUnit.test( 'getRights (Promise)', function ( assert ) {
+               this.server.respond( [ 200, { 'Content-Type': 'application/json' },
+                       '{ "query": { "userinfo": { "groups": [ "unused" ], "rights": [ "read", "edit", "createtalk" ] } } }'
+               ] );
 
-               this.server.respondWith( /meta=userinfo/, function ( request ) {
-                       request.respond( 200, { 'Content-Type': 'application/json' },
-                               '{ "query": { "userinfo": { "groups": [ "unused" ], "rights": [ "read", "edit", "createtalk" ] } } }'
-                       );
+               return mw.user.getRights().then( function ( rights ) {
+                       assert.deepEqual( rights, [ 'read', 'edit', 'createtalk' ], 'Result (promise)' );
                } );
-
-               this.server.respond();
        } );
 
        QUnit.test( 'generateRandomSessionId', function ( assert ) {