it('should promisify options', done => { request('a', { mutate (options) { return options } }).finally(done) })
it('should promisify options 3', done => { request('a', { mutate () { return false } }).finally(done) })
const shouldRenderCompo = (plugin) => new Promise((resolve, reject) => { request('/settings-manager/autoReload') .then(response => { plugin.preventComponentRendering = !response.autoReload; plugin.blockerComponentProps = { blockerComponentTitle: 'components.AutoReloadBlocker.header', blockerComponentDescription: 'components.AutoReloadBlocker.description', blockerComponentIcon: 'fa-refresh', blockerComponentContent: 'renderIde', }; if (response.environment !== 'development') { plugin.preventComponentRendering = true; plugin.blockerComponentProps = { blockerComponentTitle: 'components.ProductionBlocker.header', blockerComponentDescription: 'components.ProductionBlocker.description', blockerComponentIcon: 'fa-ban', blockerComponentContent: 'renderButton', }; } return resolve(plugin); }) .catch(err => reject(err)); });
export async function query (params) { return request({ url: users, method: 'get', data: params, }) }
window.podlovePlayer = (selector, episode, additional = {}) => { const node = findNode(selector) const nodeHtml = node.innerHTML node.innerHTML = '' return requestConfig(episode) .then(config => Promise.resolve(merge(config, additional)) .then(setPublicPath) .then(createPlayerDom) .then(sandboxFromSelector(node)) // Set Title for accessibility .then(setAccessibilityAttributes(config)) .then(resizer) .then(sandboxWindow(['PODLOVE_STORE'])) .then(dispatchUrlParameters) ) .catch(err => { node.innerHTML = nodeHtml console.group(`Can't load Podlove Webplayer ${version}`) console.error('selector', selector) console.error('config', episode) console.error(err) console.groupEnd() }) }
it('200', done => { request({ url: '' }).then(json => { expect(json.hello).to.equal('world') done() }) })
return dispatch => { request(`/orgs/${config.ownerName}`, { method: 'get' }) .then(res => { if (res.name) return dispatch(getRepoOwnerNameSucces(res.name)); return dispatch(getRepoOwnerNameError()); }) }
[INIT]: ({ dispatch }, { type, payload }) => { const transcriptsUrl = get(payload, 'transcripts') request(transcriptsUrl) .then(transformTranscript) .then(data => { return data }) .catch(() => []) .then(compose(dispatch, actions.initTranscripts)) },
getOptions = query => { const params = { limit: 20, skip: this.state.toSkip, source: this.props.relation.plugin || 'content-manager', }; // Set `query` parameter if necessary if (query) { delete params.limit, delete params.skip, params[`${this.props.relation.displayedAttribute}_contains`] = query; } // Request URL const requestUrl = `/content-manager/explorer/${this.props.relation.model || this.props.relation.collection}`; // Call our request helper (see 'utils/request') return request(requestUrl, { method: 'GET', params, }) .then(response => { const options = isArray(response) ? response.map(item => ({ value: item, label: templateObject({ mainField: this.props.relation.displayedAttribute }, item) .mainField, })) : [ { value: response, label: response[this.props.relation.displayedAttribute], }, ]; const newOptions = cloneDeep(this.state.options); options.map(option => { // Don't add the values when searching if (findIndex(newOptions, o => o.value.id === option.value.id) === -1) { return newOptions.push(option); } }); return this.setState({ options: newOptions, isLoading: false, }); }) .catch(() => { strapi.notification.error('content-manager.notification.error.relationship.fetch'); }); };
it('should translate arguments', done => { let url request('a', { mutate (options) { url = options.url return Promise.resolve({}) } }).finally(() => { expect(url).to.equal('a') done() }) })
it('403 with json', done => { window.fetch // .withArgs(...) .returns(Promise.resolve(new window.Response('{"hello":"world"}', { status: 403, headers }))) request({ url: '' }).catch(err => { expect(err.hello).to.equal('world') done() }) })
it('404', done => { window.fetch // .withArgs(...) .returns(Promise.resolve(new window.Response('Not Found', { status: 404, statusText: 'Not Found' }))) request({ url: '' }).catch(err => { expect(err).to.equal('Not Found') done() }) })
it('should NOT has question mark', done => { let url request({ url: 'a', query: {}, mutate (options) { url = options.url return Promise.resolve({}) } }).finally(() => { expect(url).to.equal('a') done() }) })
loadLatestConfirmedBlocks() { request(this.props.blocksUrl) .then(blocks => { if (!this.blockList[blocks.data.hash]) { this.blocks.unshift(blocks.data); this.blockList[blocks.data.hash] = blocks.data; this.emptyUnconfirmedBlock.height = blocks.data.height + 1; this.setState({ confirmedBlocks: this.blocks, unconfirmedBlock: this.emptyUnconfirmedBlock, }); } }); }
function makeRequest() { if (getState().app.pending) return; dispatch(getReposRequest()); request(`/search/repositories?q=${value} in:name user:${config.ownerName}`, { method: 'get', }) .then(res => { if (!res.items) return dispatch(getReposError()); return dispatch(getReposSuccess(res.items)); }, (res => { return dispatch(getReposError()); })); }
it('should replace url with params', done => { let url request({ url: '{y}a{x}b{{x}}', params: { x: 1 }, mutate (options) { url = options.url return Promise.resolve({}) } }).finally(() => { expect(url).to.equal('a1b{x}') done() }) })
var videos = ids.map(function (id) { var video = { id: id, iFrameUrl: 'https://www.youtube.com/embed/' + id + '?autoplay=1&autohide=1&origin=http://davidmiles.se', image: 'url(http://i.ytimg.com/vi/' + id + '/mqdefault.jpg)', title: ko.observable(), width: '320px', height: '180px', fill: true }; request('GET', 'https://www.googleapis.com/youtube/v3/videos?key=' + apiKey + '&fields=items(snippet(title))&part=snippet&id=' + video.id).end(function (result) { video.title(result.body.items[0].snippet.title); }); return video; });
it('should add query to url 2', done => { let url request({ url: 'a?x=1', query: { x: 1 }, mutate (options) { url = options.url return Promise.resolve({}) } }).finally(() => { expect(url).to.equal('a?x=1&x=1') done() }) })
it('should serialize body 3', done => { let body request({ method: 'POST', body: { x: 1 }, mutate (options) { body = options.body return Promise.resolve({}) } }).finally(() => { expect(body).to.equal('{"x":1}') done() }) })
it('should serialize body', done => { let url let body request({ body: { x: 1 }, mutate (options) { url = options.url body = options.body return Promise.resolve({}) } }).finally(() => { expect(url).to.equal('?x=1') expect(body).to.equal(undefined) done() }) })
const bootstrap = (plugin) => new Promise((resolve, reject) => { request('/content-manager/models', { method: 'GET' }) .then(models => { const menu = [{ name: 'Content Types', links: map(omit(models.models.models, 'plugins'), (model, key) => ({ label: model.labelPlural || model.label || key, destination: key, })), }]; plugin.leftMenuSections = menu; resolve(plugin); }) .catch(e => { strapi.notification.error('content-manager.error.model.fetch'); reject(e); }); });
getOptions = (query) => { const params = { limit: 20, source: this.props.relation.plugin || 'content-manager', }; // Set `query` parameter if necessary if (query) { params.query = query; params.queryAttribute = this.props.relation.displayedAttribute; } // Request URL const requestUrlSuffix = query && this.props.record.get(this.props.relation.alias).toJS() ? this.props.record.get(this.props.relation.alias).toJS() : ''; const requestUrl = `/content-manager/explorer/${this.props.relation.model || this.props.relation.collection}/${requestUrlSuffix}`; // Call our request helper (see 'utils/request') return request(requestUrl, { method: 'GET', params, }) .then(response => { const options = isArray(response) ? response.map(item => ({ value: item, label: templateObject({ mainField: this.props.relation.displayedAttribute }, item).mainField, })) : [{ value: response, label: response[this.props.relation.displayedAttribute], }]; return { options }; }) .catch(() => { strapi.notification.error('content-manager.notification.error.relationship.fetch'); }); }
import request from 'utils/request'; const url = '/api/game'; const api = { create(data) { return request({ method: 'post', url: url, data: data }); }, query(data) { return request({ method: 'get', url: url, params: data }); }, getUserGameData(data) { return request({ method: 'get', url: url, params: data }); }, }; export default api;
}, [SET_ENV_I18N] (state, { payload, meta }) { if (meta === PROMISE_SUCCESS) { Object.assign(state, { i18n: payload }) localEnv.set(state) } } } const actions = { setEnv ({ commit }, payload) { commit(SET_ENV, payload) if (payload.lang) { commit(SET_ENV_I18N, request(`./i18n/${payload.lang}.json`, { proxyFlag : false })) } } } export default { state, getters, actions, mutations }
it('should NOT ok', () => { expect(request()).to.equal(undefined) expect(request('a', 'b')).to.equal(undefined) expect(request(false)).to.equal(undefined) })
it('should ok', done => { request('a').then(json => { expect(json.hello).to.equal('world') done() }) })