Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F2752499
mediawiki.ForeignRest.test.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
mediawiki.ForeignRest.test.js
View Options
QUnit
.
module
(
'mediawiki.ForeignRest'
,
(
hooks
)
=>
{
const
CoreForeignApi
=
require
(
'mediawiki.ForeignApi.core'
).
ForeignApi
;
const
CoreForeignRest
=
require
(
'mediawiki.ForeignApi.core'
).
ForeignRest
;
hooks
.
beforeEach
(
function
()
{
this
.
server
=
this
.
sandbox
.
useFakeServer
();
this
.
server
.
respondImmediately
=
true
;
this
.
actionApi
=
new
CoreForeignApi
(
'http://test.example.com/api.php'
);
}
);
QUnit
.
test
(
'get()'
,
function
(
assert
)
{
const
api
=
new
CoreForeignRest
(
'http://test.example.com/rest.php'
,
this
.
actionApi
);
this
.
server
.
respond
(
(
request
)
=>
{
assert
.
strictEqual
(
request
.
method
,
'GET'
);
assert
.
strictEqual
(
request
.
url
,
'http://test.example.com/rest.php/test/rest/path'
);
request
.
respond
(
200
,
{
'Content-Type'
:
'application/json'
},
'{}'
);
}
);
return
api
.
get
(
'/test/rest/path'
).
then
(
(
data
)
=>
{
assert
.
deepEqual
(
data
,
{},
'If request succeeds without errors, resolve deferred'
);
}
);
}
);
QUnit
.
test
(
'post()'
,
function
(
assert
)
{
const
api
=
new
CoreForeignRest
(
'http://test.example.com/rest.php'
,
this
.
actionApi
);
this
.
server
.
respond
(
(
request
)
=>
{
assert
.
strictEqual
(
request
.
method
,
'POST'
,
'Method should be POST'
);
assert
.
strictEqual
(
request
.
url
,
'http://test.example.com/rest.php/test/bla/bla/bla'
,
'Url should be correct'
);
assert
.
true
(
/^application\/json/
.
test
(
request
.
requestHeaders
[
'Content-Type'
]
),
'Should set JSON content-type'
);
assert
.
strictEqual
(
request
.
requestHeaders
.
authorization
,
'my_token'
,
'Should pass request header'
);
assert
.
deepEqual
(
JSON
.
parse
(
request
.
requestBody
),
{
param
:
'value'
},
'Body should be correct'
);
request
.
respond
(
201
,
{
'Content-Type'
:
'application/json'
},
'{}'
);
}
);
return
api
.
post
(
'/test/bla/bla/bla'
,
{
param
:
'value'
},
{
authorization
:
'my_token'
}
).
then
(
(
data
)
=>
{
assert
.
deepEqual
(
data
,
{},
'If request succeeds without errors, resolve deferred'
);
}
);
}
);
QUnit
.
test
(
'http error'
,
function
(
assert
)
{
const
api
=
new
CoreForeignRest
(
'http://test.example.com/rest.php'
,
this
.
actionApi
);
this
.
server
.
respond
(
[
404
,
{},
'FAIL'
]
);
api
.
get
(
'/test/rest/path'
)
.
fail
(
(
errorCode
)
=>
{
assert
.
strictEqual
(
errorCode
,
'http'
,
'API error should reject the deferred'
);
}
)
.
always
(
assert
.
async
()
);
}
);
}
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jul 3, 20:04 (1 d, 11 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
d2/bc/4a0e96286ad0577597acee271503
Default Alt Text
mediawiki.ForeignRest.test.js (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment