Skip to content

Commit

Permalink
fixing broken tests and cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
dopecodez committed Apr 2, 2021
1 parent bfceabf commit 8964ecc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
5 changes: 1 addition & 4 deletions source/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ async function makeRequest(params: any, redirect = true): Promise<any> {
});
const response = await fetch(encodeURI(API_URL + searchParam), options);
const result = await response.json();
console.log(result);
// const result = JSON.parse(responseBuffer.toString());
return result;
} catch (error) {
throw new wikiError(error);
Expand All @@ -50,8 +48,7 @@ export async function makeRestRequest(path: string, redirect = true): Promise<an
}
}
const response = await fetch(encodeURI(REST_API_URL + path), options);
const responseBuffer = await response.buffer();
const result = JSON.parse(responseBuffer.toString());
const result = await response.json();
return result;
} catch (error) {
throw new wikiError(error);
Expand Down
7 changes: 3 additions & 4 deletions test/request.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import request, {makeRestRequest, setAPIUrl} from '../source/request';
import * as fetch from 'node-fetch';
import { Response } from 'node-fetch';
import { URL } from 'url';
import { wikiError } from '../source/errors';
const fetchMock = jest.spyOn(fetch, "default");

Expand All @@ -25,7 +24,7 @@ test('makeRequest method calls and returns with expected params', async () => {
fetchMock.mockImplementation(async () => { return response1 } );
await request({}, true);
expect(fetchMock).toHaveBeenCalledWith(
new URL(apiUrl + 'format=json&redirects=&action=query'),
apiUrl + 'format=json&redirects=&action=query&origin=*&',
options
);
});
Expand All @@ -34,7 +33,7 @@ test('makeRequest method calls and returns with expected params when no value pa
fetchMock.mockImplementation(async () => { return response3 } );
await request({});
expect(fetchMock).toHaveBeenCalledWith(
new URL(apiUrl + 'format=json&redirects=&action=query'),
apiUrl + 'format=json&redirects=&action=query&origin=*&',
options
);
});
Expand All @@ -51,7 +50,7 @@ test('makeRestRequest method calls and returns with expected params', async () =
fetchMock.mockImplementation(async () => { return response2 } );
await makeRestRequest("path", false);
expect(fetchMock).toHaveBeenCalledWith(
new URL(restApiUrl + 'path?redirect=false'),
restApiUrl + 'path?redirect=false',
options
);
});
Expand Down

0 comments on commit 8964ecc

Please sign in to comment.