Added warning for improper ending of a token
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki.api / mediawiki.ForeignApi.test.js
1 ( function ( mw ) {
2 QUnit.module( 'mediawiki.ForeignApi', QUnit.newMwEnvironment( {
3 setup: function () {
4 this.server = this.sandbox.useFakeServer();
5 this.server.respondImmediately = true;
6 this.clock = this.sandbox.useFakeTimers();
7 },
8 teardown: function () {
9 // https://github.com/jquery/jquery/issues/2453
10 this.clock.tick();
11 }
12 } ) );
13
14 QUnit.test( 'origin is included in GET requests', function ( assert ) {
15 QUnit.expect( 1 );
16 var api = new mw.ForeignApi( '//localhost:4242/w/api.php' );
17
18 this.server.respond( function ( request ) {
19 assert.ok( request.url.match( /origin=/ ), 'origin is included in GET requests' );
20 request.respond( 200, { 'Content-Type': 'application/json' }, '[]' );
21 } );
22
23 api.get( {} );
24 } );
25
26 QUnit.test( 'origin is included in POST requests', function ( assert ) {
27 QUnit.expect( 2 );
28 var api = new mw.ForeignApi( '//localhost:4242/w/api.php' );
29
30 this.server.respond( function ( request ) {
31 assert.ok( request.requestBody.match( /origin=/ ), 'origin is included in POST request body' );
32 assert.ok( request.url.match( /origin=/ ), 'origin is included in POST request URL, too' );
33 request.respond( 200, { 'Content-Type': 'application/json' }, '[]' );
34 } );
35
36 api.post( {} );
37 } );
38
39 }( mediaWiki ) );