Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return this.api.count('foo').then(function() {
const opts = fetchMock.lastOptions('count')
should(opts.method).equal('GET')
should(opts.body).be.null()
})
})
it("Should getBudgets and validate the request is sent correctly", async () => {
let budgetSummary = budgetSummaryFactory.build();
fetchMock.mock("*", budgetSummary);
let ynab: ynabApi = new ynabApi(API_KEY, BASE_URL);
const getBudgetsResponse = await ynab.budgets.getBudgets(0);
expect(fetchMock.calls().matched.length, "fetchMock calls").to.equal(1);
expect(fetchMock.lastUrl()).to.equal(`${BASE_URL}/budgets`);
expect(fetchMock.lastOptions().method).to.equal("GET");
expect(fetchMock.lastOptions().headers).to.deep.equal({
Authorization: "Bearer API_KEY"
});
});
});
return this.api.logout('foo', 'bar').then(() => {
opts = fetchMock.lastOptions('logout')
should(opts.headers.has('sessionID')).be.ok()
this.api.login('foo', 'bar')
opts = fetchMock.lastOptions('login')
should(opts.headers.has('sessionID')).not.be.ok()
})
})
it("Should getBudgets and validate the request is sent correctly", async () => {
let budgetSummary = budgetSummaryFactory.build();
fetchMock.mock("*", budgetSummary);
let ynab: ynabApi = new ynabApi(API_KEY, BASE_URL);
const getBudgetsResponse = await ynab.budgets.getBudgets(0);
expect(fetchMock.calls().matched.length, "fetchMock calls").to.equal(1);
expect(fetchMock.lastUrl()).to.equal(`${BASE_URL}/budgets`);
expect(fetchMock.lastOptions().method).to.equal("GET");
expect(fetchMock.lastOptions().headers).to.deep.equal({
Authorization: "Bearer API_KEY"
});
});
});
const complete = () => {
try {
const calls = fetchMock.calls('begin:batch');
expect(calls.length).toBe(1);
expect(nextCalls).toBe(2);
const options = fetchMock.lastOptions('begin:batch');
expect(options.credentials).toEqual('two');
const { headers } = options;
expect(headers['apollographql-client-name']).toBeDefined();
expect(headers['apollographql-client-name']).toEqual(
clientAwareness.name,
);
expect(headers['apollographql-client-version']).toBeDefined();
expect(headers['apollographql-client-version']).toEqual(
clientAwareness.version,
);
completions++;
if (completions === 2) {
done();
it('should post the ids and metadata to /entities/multipleupdate', async () => {
const values = { metadata: { text: 'document text' } };
const ids = ['1', '2'];
const request = new RequestParams({ values, ids });
const response = await entitiesAPI.multipleUpdate(request);
expect(JSON.parse(backend.lastOptions(`${APIURL}entities/multipleupdate`).body)).toEqual({ ids, values });
expect(response).toEqual({ backednResponse: 'test multiple' });
});
});
xhr('get-200').then(() => {
const options = fetchMock.lastOptions();
expect(options.credentials).to.equal('same-origin');
expect(Object.keys(options.headers).length).to.equal(2);
expect(options.headers['Content-Type']).to.equal('application/json');
expect(options.headers['Accept']).to.equal('application/json');
done();
}).catch(done);
});
const expectedActions = [
{ type: types.THESAURI_SAVED },
{ type: notificationsTypes.NOTIFY, notification: { message: 'Thesaurus saved', type: 'success', id: 'unique_id' } },
{ type: 'rrf/change', model: 'thesauri.data', value: { testBackendResult: 'ok' }, silent: false, multi: false, external: true }
];
const store = mockStore({});
const data = { name: 'Secret list of things', values: [] };
store.dispatch(actions.saveThesauri(data))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
})
.then(done)
.catch(done.fail);
expect(JSON.parse(backend.lastOptions(`${APIURL}thesauris`).body)).toEqual(data);
});
});