Skip to content

Commit

Permalink
test for sent data
Browse files Browse the repository at this point in the history
  • Loading branch information
70ray committed Feb 5, 2022
1 parent ac7f34d commit 32647c2
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions SETUP/tests/jsTests/ajaxTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ QUnit.module("Ajax test", function() {

QUnit.test("Return correct data", function (assert) {
function fetchPromise() {
const blob = new Blob([JSON.stringify("mydata")], {type : 'application/json'});
const blob = new Blob([JSON.stringify({key: "value"})], {type : 'application/json'});
const init = {status: 200, headers: {'content-type': 'application/json'}};
return Promise.resolve(new Response(blob, init));
}

return ajax("GET", "myUrl", {}, {}, fetchPromise)
.then(function(data) {
assert.strictEqual(data, "mydata");
assert.deepEqual(data, {key: "value"});
});
});

Expand Down Expand Up @@ -57,4 +57,20 @@ QUnit.module("Ajax test", function() {
});
});

QUnit.test("Check sent data", function (assert) {
function fetchPromise(url, options) {
assert.strictEqual(url.href, "https://www.dummy.org/api/index.php?url=myUrl&querykey=queryvalue");
assert.strictEqual(options.method, "POST");
assert.strictEqual(options.headers['Content-Type'], 'application/json');
assert.strictEqual(options.headers["X-API-KEY"], "SESSION");
assert.strictEqual(options.headers.Accept, 'application/json');
assert.strictEqual(options.body, "{\"datakey\":\"datavalue\"}");
const blob = new Blob([JSON.stringify("mydata")], {type : 'application/json'});
const init = {status: 200, headers: {'content-type': 'application/json'}};
return Promise.resolve(new Response(blob, init));
}

return ajax("POST", "myUrl", {querykey: "queryvalue"}, {datakey: "datavalue"}, fetchPromise)
.then();
});
});

0 comments on commit 32647c2

Please sign in to comment.