834479d56f
ember-cli-api-double has been upgraded for 3 things: 1. Use the correct configuration flags 2. Automatically include the necessary files to enable the api doubles without requiring a server. This can be disabled to provide custom functionality (so we can stitch our BDD style testing in with this) 3. When used statically, read the cookies from the users browser to enable basic ad-hoc double editing (e.g. CONSUL_SERVICE_COUNT=100000) Once upgraded we've now moved the config to the correct place, added a new environment (staging) to use the static-style of doubles The test environment continues to use custom cookie setting and url checking so we disable this 'auto importing' by setting 'auto-import' to false for the configuration for the addon. We also added a couple of new package script targets to explicitly serve or build the UI with the entirely static UI.
41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
import config from 'consul-ui/config/environment';
|
|
|
|
import apiDouble from '@hashicorp/ember-cli-api-double';
|
|
import setCookies from 'consul-ui/tests/helpers/set-cookies';
|
|
import typeToURL from 'consul-ui/tests/helpers/type-to-url';
|
|
|
|
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);
|
|
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 || {},
|
|
headers: {},
|
|
query: [...url.searchParams.keys()].reduce(function(prev, key) {
|
|
prev[key] = url.searchParams.get(key);
|
|
return prev;
|
|
}, {}),
|
|
},
|
|
{
|
|
set: function() {},
|
|
status: function() {
|
|
return this;
|
|
},
|
|
send: function(content) {
|
|
resolve(JSON.parse(content));
|
|
},
|
|
},
|
|
function() {}
|
|
);
|
|
});
|
|
};
|
|
export default api;
|