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