Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('pandas.get()', async () => {
mockFetch.mockResponse(fs.readFileSync(__dirname + '/data.csv'));
var data = await pandas.get('data.csv');
expect(data).toEqual([
{
site: 'SITE1',
parameter: 'PARAM1',
data: [
{ date: '2014-01-01', value: 0.5 },
{ date: '2014-01-02', value: 0.1 }
]
},
{
site: 'SITE2',
parameter: 'PARAM1',
data: [
{ date: '2014-01-01', value: 0.5 },
{ date: '2014-01-02', value: 0.5 }
it('should call httpGet method with the proper accept header', async () => {
mockResponse(mockDotResponse, { status: 200 });
const resource = new Resource(
'testOrg',
'testProject',
mockResourceResponse,
);
await resource.getAs(ResourceGetFormat.DOT);
expect(mock.calls[0][0]).toEqual(mockResourceResponse['_self']);
expect(mock.calls[0][1].headers.get('Accept')).toBe(
'text/vnd.graphviz',
);
});
});
it('should request the raw file', async () => {
mockResponse(fakeFile, { status: 200 });
const file = new NexusFile('testOrg', 'testProject', mockFileResponse);
await file.getFile();
const headers = mock.calls[0][1].headers;
expect(headers.get('Accept')).toBe('*/*');
expect(file.rawFile).toEqual(btoa(fakeFile));
});
});
test('Should contain data with valid url', async (done) => {
fetch.mockResponse(JSON.stringify(simpleRecordsExpected));
const component = shallow();
await (component.instance() as any).processRequest({});
expect(component.state('data')).toEqual(simpleRecordsExpected.Payload);
done();
});
it('should get the Sparql view', async () => {
mockResponse(JSON.stringify(mockSparqlViewResponse));
const view: SparqlView = await SparqlView.get(orgLabel, projectLabel);
expect(mock.calls.length).toBe(1);
expect(view.id).toBe(mockSparqlViewResponse['@id']);
expect(view.deprecated).toBe(mockSparqlViewResponse._deprecated);
expect(view.orgLabel).toBe('my-org');
expect(view.projectLabel).toBe('example');
expect(view.rev).toBe(mockSparqlViewResponse._rev);
expect(view.type).toEqual(mockSparqlViewResponse['@type']);
expect(view.uuid).toBe(mockSparqlViewResponse._uuid);
});
it('should successfully parse prepare File', async () => {
const payload = { message: 'success' };
mockResponse(JSON.stringify(payload), { status: 200 });
const blob = new Blob(['abc'], { type: 'tet/plain ' });
httpPost('/endpoint', blob, {
sendAs: HttpConfigTypes.FILE,
});
expect(mock.calls[0][1].body).toEqual(blob);
});
it('should throw an error', async () => {
beforeEach(() => {
mockResponse('{}');
});
beforeEach(() => {
mockResponse(JSON.stringify(mockResourceResponse), { status: 200 });
});
beforeEach(() => {
mockResponse('{}');
});
afterEach(() => {
it('request with custom agent', async () => {
const response = { a: 3 };
const mockResponse = jest.fn(() =>
Promise.resolve({
body: JSON.stringify(response),
init: {
headers: {
'Content-type': 'application/json;',
},
},
})
);
fetch.mockResponse(mockResponse);
class MockedAgent {
requests() {}
destroy() {}
}
http({ agent: { http: new MockedAgent() as any, https: new MockedAgent() as any } }).init(
new Context({ request: { url: 'http://test.com/api' } }),
next,
null
);
await new Promise((res) => {
next.mockImplementation(res);
});