2019-08-31 20:51:14 -07:00
|
|
|
import { getJSON, postJSON, deleteJSON, putJSON, getHeaders } from '@datahub/utils/api/fetcher';
|
2017-09-19 13:32:04 -07:00
|
|
|
import { module, test } from 'qunit';
|
2017-11-30 10:33:07 -08:00
|
|
|
import sinon from 'sinon';
|
2019-08-31 20:51:14 -07:00
|
|
|
import { TestContext } from 'ember-test-helpers';
|
2017-09-19 13:32:04 -07:00
|
|
|
|
2018-08-09 23:25:55 -07:00
|
|
|
module('Unit | Utility | api/fetcher', function(hooks) {
|
2019-08-31 20:51:14 -07:00
|
|
|
hooks.beforeEach(function(this: TestContext & { xhr: any }) {
|
2017-11-30 10:33:07 -08:00
|
|
|
this.xhr = sinon.useFakeXMLHttpRequest();
|
2018-08-09 23:25:55 -07:00
|
|
|
});
|
2017-09-19 13:32:04 -07:00
|
|
|
|
2019-08-31 20:51:14 -07:00
|
|
|
hooks.afterEach(function(this: TestContext & { xhr: any }) {
|
2017-11-30 10:33:07 -08:00
|
|
|
this.xhr.restore();
|
2018-08-09 23:25:55 -07:00
|
|
|
});
|
2017-11-30 10:33:07 -08:00
|
|
|
|
2018-08-09 23:25:55 -07:00
|
|
|
test('each http request function exists', function(assert) {
|
|
|
|
[getJSON, postJSON, deleteJSON, putJSON, getHeaders].forEach(httpRequest =>
|
|
|
|
assert.ok(typeof httpRequest === 'function', `${httpRequest} is a function`)
|
|
|
|
);
|
|
|
|
});
|
2017-11-30 10:33:07 -08:00
|
|
|
|
2018-08-09 23:25:55 -07:00
|
|
|
test('each http request function returns a Promise / thennable', function(assert) {
|
|
|
|
[getJSON, postJSON, deleteJSON, putJSON, getHeaders].forEach(httpRequest =>
|
2019-08-31 20:51:14 -07:00
|
|
|
assert.ok(
|
|
|
|
typeof httpRequest({ url: '' }).then === 'function',
|
|
|
|
`${httpRequest} returns a Promise object or thennable`
|
|
|
|
)
|
2018-08-09 23:25:55 -07:00
|
|
|
);
|
|
|
|
});
|
2017-09-19 13:32:04 -07:00
|
|
|
});
|