summaryrefslogtreecommitdiff
path: root/tests/qunit/suites/resources/mediawiki.api/mediawiki.ForeignApi.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'tests/qunit/suites/resources/mediawiki.api/mediawiki.ForeignApi.test.js')
-rw-r--r--tests/qunit/suites/resources/mediawiki.api/mediawiki.ForeignApi.test.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/qunit/suites/resources/mediawiki.api/mediawiki.ForeignApi.test.js b/tests/qunit/suites/resources/mediawiki.api/mediawiki.ForeignApi.test.js
new file mode 100644
index 00000000..9d0fdf54
--- /dev/null
+++ b/tests/qunit/suites/resources/mediawiki.api/mediawiki.ForeignApi.test.js
@@ -0,0 +1,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 ) );