Merge "Define 'MW_UPDATER' when running update.php"
[mediawiki.git] / tests / qunit / suites / resources / mediawiki.api / mediawiki.api.test.js
blob9eda75cef5a8366c7b233cd6583a123a8bc5eae3
1 ( function ( mw ) {
2         QUnit.module( 'mediawiki.api', QUnit.newMwEnvironment() );
4         QUnit.asyncTest( 'Basic functionality', function ( assert ) {
5                 var api, d1, d2, d3;
6                 QUnit.expect( 3 );
8                 api = new mw.Api();
10                 d1 = api.get( {} )
11                         .done( function ( data ) {
12                                 assert.deepEqual( data, [], 'If request succeeds without errors, resolve deferred' );
13                         } );
15                 d2 = api.get( {
16                         action: 'doesntexist'
17                 } )
18                         .fail( function ( errorCode ) {
19                                 assert.equal( errorCode, 'unknown_action', 'API error (e.g. "unknown_action") should reject the deferred' );
20                         } );
22                 d3 = api.post( {} )
23                         .done( function ( data ) {
24                                 assert.deepEqual( data, [], 'Simple POST request' );
25                         } );
27                 // After all are completed, continue the test suite.
28                 QUnit.whenPromisesComplete( d1, d2, d3 ).always( function () {
29                         QUnit.start();
30                 } );
31         } );
33         QUnit.asyncTest( 'Deprecated callback methods', function ( assert ) {
34                 var api, d1, d2, d3;
35                 QUnit.expect( 3 );
37                 api = new mw.Api();
39                 d1 = api.get( {}, function () {
40                         assert.ok( true, 'Function argument treated as success callback.' );
41                 } );
43                 d2 = api.get( {}, {
44                         ok: function () {
45                                 assert.ok( true, '"ok" property treated as success callback.' );
46                         }
47                 } );
49                 d3 = api.get( {
50                         action: 'doesntexist'
51                 }, {
52                         err: function () {
53                                 assert.ok( true, '"err" property treated as error callback.' );
54                         }
55                 } );
57                 QUnit.whenPromisesComplete( d1, d2, d3 ).always( function () {
58                         QUnit.start();
59                 } );
60         } );
61 }( mediaWiki ) );