github.com/DerekStrickland/consul@v1.4.5/ui-v2/tests/helpers/api.js (about) 1 import getAPI from '@hashicorp/ember-cli-api-double'; 2 import setCookies from 'consul-ui/tests/helpers/set-cookies'; 3 import typeToURL from 'consul-ui/tests/helpers/type-to-url'; 4 import config from 'consul-ui/config/environment'; 5 const apiConfig = config['ember-cli-api-double']; 6 let path = '/consul-api-double'; 7 let reader; 8 if (apiConfig) { 9 const temp = apiConfig.endpoints[0].split('/'); 10 reader = apiConfig.reader; 11 temp.pop(); 12 path = temp.join('/'); 13 } 14 const api = getAPI(path, setCookies, typeToURL, reader); 15 export const get = function(_url, options = { headers: { cookie: {} } }) { 16 const url = new URL(_url, 'http://localhost'); 17 return new Promise(function(resolve) { 18 return api.api.serve( 19 { 20 method: 'GET', 21 path: url.pathname, 22 url: url.href, 23 cookies: options.headers.cookie || {}, 24 headers: {}, 25 query: [...url.searchParams.keys()].reduce(function(prev, key) { 26 prev[key] = url.searchParams.get(key); 27 return prev; 28 }, {}), 29 }, 30 { 31 set: function() {}, 32 status: function() { 33 return this; 34 }, 35 send: function(content) { 36 resolve(JSON.parse(content)); 37 }, 38 }, 39 function() {} 40 ); 41 }); 42 }; 43 export default api;