Update formatting
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki.api / mediawiki.api.test.js
1 ( function ( mw ) {
2 QUnit.module( 'mediawiki.api', QUnit.newMwEnvironment() );
3
4 QUnit.asyncTest( 'Basic functionality', function ( assert ) {
5 var api, d1, d2, d3;
6 QUnit.expect( 3 );
7
8 api = new mw.Api();
9
10 d1 = api.get( {} )
11 .done( function ( data ) {
12 assert.deepEqual( data, [], 'If request succeeds without errors, resolve deferred' );
13 } );
14
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 } );
21
22 d3 = api.post( {} )
23 .done( function ( data ) {
24 assert.deepEqual( data, [], 'Simple POST request' );
25 } );
26
27 // After all are completed, continue the test suite.
28 QUnit.whenPromisesComplete( d1, d2, d3 ).always( function () {
29 QUnit.start();
30 } );
31 } );
32
33 QUnit.asyncTest( 'Deprecated callback methods', function ( assert ) {
34 var api, d1, d2, d3;
35 QUnit.expect( 3 );
36
37 api = new mw.Api();
38
39 d1 = api.get( {}, function () {
40 assert.ok( true, 'Function argument treated as success callback.' );
41 } );
42
43 d2 = api.get( {}, {
44 ok: function () {
45 assert.ok( true, '"ok" property treated as success callback.' );
46 }
47 } );
48
49 d3 = api.get( {
50 action: 'doesntexist'
51 }, {
52 err: function () {
53 assert.ok( true, '"err" property treated as error callback.' );
54 }
55 } );
56
57 QUnit.whenPromisesComplete( d1, d2, d3 ).always( function () {
58 QUnit.start();
59 } );
60 } );
61 }( mediaWiki ) );