2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-14 13:18:55 +00:00
|
|
|
*/
|
|
|
|
|
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'];
|
2020-02-10 10:04:55 +00:00
|
|
|
const api = apiDouble(addon, setCookies, typeToURL);
|
2022-09-15 08:43:17 +00:00
|
|
|
export const get = function (_url, options = { headers: { cookie: {} } }) {
|
2018-07-30 16:55:44 +00:00
|
|
|
const url = new URL(_url, 'http://localhost');
|
2022-09-15 08:43:17 +00:00
|
|
|
return new Promise(function (resolve) {
|
2018-07-30 16:55:44 +00:00
|
|
|
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: {},
|
2022-09-15 08:43:17 +00:00
|
|
|
query: [...url.searchParams.keys()].reduce(function (prev, key) {
|
2018-07-30 16:55:44 +00:00
|
|
|
prev[key] = url.searchParams.get(key);
|
|
|
|
return prev;
|
|
|
|
}, {}),
|
|
|
|
},
|
|
|
|
{
|
2022-09-15 08:43:17 +00:00
|
|
|
set: function () {},
|
|
|
|
status: function () {
|
2018-10-03 08:54:07 +00:00
|
|
|
return this;
|
|
|
|
},
|
2022-09-15 08:43:17 +00:00
|
|
|
send: function (content) {
|
2018-07-30 16:55:44 +00:00
|
|
|
resolve(JSON.parse(content));
|
|
|
|
},
|
|
|
|
},
|
2022-09-15 08:43:17 +00:00
|
|
|
function () {}
|
2018-07-30 16:55:44 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
export default api;
|