Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let API_URL = 'https://en.wikipedia.org/w/api.php?',
async function callAPI(url: string) {
const options: AxiosRequestConfig = {
headers: {
"User-Agent": USER_AGENT,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #77 & #78

"Api-User-Agent": USER_AGENT,
},
};
Expand Down
1 change: 0 additions & 1 deletion test/pdf.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as request from '../source/request';
import wiki from "../source/index";
import { htmlString, notFoundJson } from './samples';
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused

import { pdfError } from '../source/errors';
import Page, { pdf } from '../source/page';
import { pageJson } from './samples';
Expand Down
9 changes: 7 additions & 2 deletions test/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import request, {makeRestRequest, setAPIUrl, returnRestUrl, setUserAgent} from '
import { wikiError } from '../source';
const fetchMock = jest.spyOn(axios, "get");

const expectedDefaultUserAgent = "wikipedia (https://github.com/dopecodez/Wikipedia/)";

const options: AxiosRequestConfig = {
headers: {
'Api-User-Agent': 'wikipedia (https://github.com/dopecodez/Wikipedia/)'
"User-Agent": expectedDefaultUserAgent,
'Api-User-Agent': expectedDefaultUserAgent
}
}
const baseConfig : AxiosResponse['config'] = { headers: new AxiosHeaders()};
Expand Down Expand Up @@ -86,11 +89,13 @@ test('Set language returns api url with language set', () => {

test('Set user agent and use it to call the api', async () => {
setUserAgent("testUser");
const userAgentOverride = "testUser";
fetchMock.mockImplementation(async () => { return response1 } );
await request({}, true);
const modifiedOptions : AxiosRequestConfig = {
headers: {
'Api-User-Agent': 'testUser'
"User-Agent": userAgentOverride,
'Api-User-Agent': userAgentOverride
}
}
expect(fetchMock).toHaveBeenCalledWith(
Expand Down
Loading