2019-08-02 11:36:22 +00:00
|
|
|
import config from 'consul-ui/config/environment';
|
|
|
|
|
|
|
|
import apiDouble from '@hashicorp/ember-cli-api-double';
|
2018-05-11 12:47:21 +00:00
|
|
|
import setCookies from 'consul-ui/tests/helpers/set-cookies';
|
|
|
|
import typeToURL from 'consul-ui/tests/helpers/type-to-url';
|
2019-08-02 11:36:22 +00:00
|
|
|
|
|
|
|
const addon = config['@hashicorp/ember-cli-api-double'];
|
|
|
|
const temp = addon.endpoints[0].split('/');
|
|
|
|
temp.pop();
|
|
|
|
const path = temp.join('/');
|
|
|
|
const api = apiDouble(path, setCookies, typeToURL);
|
2018-07-30 16:55:44 +00:00
|
|
|
export const get = function(_url, options = { headers: { cookie: {} } }) {
|
|
|
|
const url = new URL(_url, 'http://localhost');
|
|
|
|
return new Promise(function(resolve) {
|
|
|
|
return api.api.serve(
|
|
|
|
{
|
|
|
|
method: 'GET',
|
|
|
|
path: url.pathname,
|
|
|
|
url: url.href,
|
|
|
|
cookies: options.headers.cookie || {},
|
2018-10-19 15:17:02 +00:00
|
|
|
headers: {},
|
2018-07-30 16:55:44 +00:00
|
|
|
query: [...url.searchParams.keys()].reduce(function(prev, key) {
|
|
|
|
prev[key] = url.searchParams.get(key);
|
|
|
|
return prev;
|
|
|
|
}, {}),
|
|
|
|
},
|
|
|
|
{
|
2018-08-29 09:00:15 +00:00
|
|
|
set: function() {},
|
2018-10-03 08:54:07 +00:00
|
|
|
status: function() {
|
|
|
|
return this;
|
|
|
|
},
|
2018-07-30 16:55:44 +00:00
|
|
|
send: function(content) {
|
|
|
|
resolve(JSON.parse(content));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
function() {}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
export default api;
|