Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('posts to the DataLad /datasets/{dsId}/snapshots/{snapshot} endpoint', async done => {
const tag = 'snapshot'
const dsId = await createDataset()
// Reset call count for request.post
request.post.mockClear()
request.__setMockResponse({ body: {} })
await createSnapshot(dsId, tag, false)
expect(request.post).toHaveBeenCalledTimes(1)
expect(request.post).toHaveBeenCalledWith(
expect.stringContaining(
`${config.datalad.uri}/datasets/${dsId}/snapshots/${tag}`,
),
)
done()
})
})
test('Should make a successful POST request', done => {
superagent.__setMockResponse({
status: 200,
data: 'some data'
});
var HttpManager = require('../src/http-manager');
var request = Request.builder()
.withHost('such.api.wow')
.withPort(1337)
.withScheme('http')
.build();
HttpManager.post(request, function(errorObject) {
done(errorObject);
});
});
it('handles a corrupted response', end => {
request.post.mockClear()
request.__setMockResponse({
body: Buffer.from('0x5f3759df', 'hex'),
})
getDescriptionObject('ds000001')([
{ filename: 'dataset_description.json', id: '12345' },
]).then(description => {
expect(description).toEqual(defaultDescription)
end()
})
})
it('works without a dataset_description.json being present', end => {
it('on success sets the totalRecords on the pager and sets data-state to loaded', () => {
Request.__setMockResponse({
status() {
return 200;
},
ok() {
return true;
},
body: {
records: 1
}
});
instance.emitOnChangeCallback('data', options);
jest.runTimersToTime(251);
wrapper.update();
const pager = wrapper.find(Pager);
expect(pager.props().totalRecords).toEqual('1');
beforeEach(() => {
Request.__setMockResponse(response);
Request.__setMockError(error);
jest.useFakeTimers();
});
beforeEach(() => {
Request.__setMockResponse({
status() {
return 200;
},
ok() {
return true;
},
body: {
data: [{
records: 1,
items: [ 1 ],
page: 1
}]
}
});
Request.abort = jest.fn().mockReturnThis();
wrapper = mount();
beforeEach(() => {
Request.__setMockResponse({
status() {
return 500;
},
ok() {
return false;
},
body: {
message_type: 'error'
}
});
Request.__setMockError({
message: 'Unsuccessful HTTP response'
});
});