Skip to content

Commit

Permalink
Merge branch 'main' into user/vidorteg/fix-contributing
Browse files Browse the repository at this point in the history
  • Loading branch information
vidorteg committed Jan 30, 2024
2 parents d145d26 + 69f9bd2 commit 84e63a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export function fetchUri(uri: string, options: https.RequestOptions = {}): Promi
rejectUnauthorized: false,
...parsedUrl,
...options,
method: 'PUT',
} as http.RequestOptions;

get(options, response => {
Expand Down
19 changes: 19 additions & 0 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,25 @@ describe("utils", () => {
expect(fake.on).toHaveBeenNthCalledWith(2, "end", expect.any(Function));
});

it("options passed to 'get' uses PUT as HTTP verb", async () => {
// Chrome headless require 'PUT' instead of 'GET' for /json/new otherwise we get
// 'Using unsafe HTTP verb GET to invoke /json/new. The recommended way is to use PUT'
const httpGetMock = mockGetHttp;
const customError = new Error('customError');
const fakeGet = (_options: any, callback: (resp: object) => void) => {
expect(_options.method).not.toBeUndefined();
expect(_options.method).toEqual('PUT');

// after validation we can halt execution to resolve the promise chain.
return { on: () => { throw customError } }
};

httpGetMock.mockImplementation(fakeGet);
await utils.fetchUri("http://somedomain.com/json/list").catch((error: any) => {
expect(error).toEqual(customError);
})
});

it("requests http url correctly", async () => {
const expectedHttpResponse = "[{},{}]";
mockGetHttp.mockImplementation(
Expand Down

0 comments on commit 84e63a3

Please sign in to comment.