Merge "output: Narrow Title type hint to LinkTarget"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki.api / mediawiki.ForeignApi.test.js
1 ( function () {
2 QUnit.module( 'mediawiki.ForeignApi', QUnit.newMwEnvironment( {
3 setup: function () {
4 this.server = this.sandbox.useFakeServer();
5 this.server.respondImmediately = true;
6 }
7 } ) );
8
9 QUnit.test( 'origin is included in GET requests', function ( assert ) {
10 var api = new mw.ForeignApi( '//localhost:4242/w/api.php' );
11
12 this.server.respond( function ( request ) {
13 assert.ok( request.url.match( /origin=/ ), 'origin is included in GET requests' );
14 request.respond( 200, { 'Content-Type': 'application/json' }, '[]' );
15 } );
16
17 return api.get( {} );
18 } );
19
20 QUnit.test( 'origin is included in POST requests', function ( assert ) {
21 var api = new mw.ForeignApi( '//localhost:4242/w/api.php' );
22
23 this.server.respond( function ( request ) {
24 assert.ok( request.requestBody.match( /origin=/ ), 'origin is included in POST request body' );
25 assert.ok( request.url.match( /origin=/ ), 'origin is included in POST request URL, too' );
26 request.respond( 200, { 'Content-Type': 'application/json' }, '[]' );
27 } );
28
29 return api.post( {} );
30 } );
31
32 QUnit.test( 'origin is not included in same-origin GET requests', function ( assert ) {
33 var apiUrl = location.protocol + '//' + location.host + '/w/api.php',
34 api = new mw.ForeignApi( apiUrl );
35
36 this.server.respond( function ( request ) {
37 assert.strictEqual( request.url.match( /origin=.*?(?:&|$)/ ), null, 'origin is not included in GET requests' );
38 request.respond( 200, { 'Content-Type': 'application/json' }, '[]' );
39 } );
40
41 return api.get( {} );
42 } );
43
44 QUnit.test( 'origin is not included in same-origin POST requests', function ( assert ) {
45 var apiUrl = location.protocol + '//' + location.host + '/w/api.php',
46 api = new mw.ForeignApi( apiUrl );
47
48 this.server.respond( function ( request ) {
49 assert.strictEqual( request.requestBody.match( /origin=.*?(?:&|$)/ ), null, 'origin is not included in POST request body' );
50 assert.strictEqual( request.url.match( /origin=.*?(?:&|$)/ ), null, 'origin is not included in POST request URL, either' );
51 request.respond( 200, { 'Content-Type': 'application/json' }, '[]' );
52 } );
53
54 return api.post( {} );
55 } );
56
57 }() );