Skip to content

Commit

Permalink
types and tests updated for the HttpProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Furter committed Mar 25, 2019
1 parent 4a59545 commit 169fceb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('ProvidersModuleFactoryTest', () => {
});

it('createXMLHttpRequest returns instance of XMLHttpRequest', () => {
expect(providersModuleFactory.createXMLHttpRequest('', 0, [{name: 'name', value: 'value'}], {})).toBeInstanceOf(
expect(providersModuleFactory.createXMLHttpRequest('', 0, [{name: 'name', value: 'value'}], {}, true)).toBeInstanceOf(
XHR
);

Expand Down
53 changes: 44 additions & 9 deletions packages/web3-providers/tests/src/providers/HttpProviderTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('HttpProviderTest', () => {

httpProvider = new HttpProvider(
'https',
{headers: [], timeout: 1, keepAlive: true},
{headers: [], timeout: 1, keepAlive: true, withCredentials: true},
providersModuleFactoryMock
);
});
Expand All @@ -47,7 +47,33 @@ describe('HttpProviderTest', () => {
});

it('constructor check with http', () => {
httpProvider = new HttpProvider('http', {headers: [], timeout: 1}, providersModuleFactoryMock);
httpProvider = new HttpProvider(
'http',
{headers: [], timeout: 1, keepAlive: true, withCredentials: true},
providersModuleFactoryMock
);

expect(httpProvider.host).toEqual('http');

expect(httpProvider.headers).toEqual([]);

expect(httpProvider.timeout).toEqual(1);

expect(httpProvider.connected).toEqual(true);

expect(httpProvider.withCredentials).toEqual(true);

expect(httpProvider.providersModuleFactory).toEqual(providersModuleFactoryMock);

expect(httpProvider.agent.httpAgent).toBeInstanceOf(http.Agent);
});

it('constructor check without the property withCredentials in the options', () => {
httpProvider = new HttpProvider(
'http',
{headers: [], timeout: 1},
providersModuleFactoryMock
);

expect(httpProvider.host).toEqual('http');

Expand All @@ -57,6 +83,8 @@ describe('HttpProviderTest', () => {

expect(httpProvider.connected).toEqual(true);

expect(httpProvider.withCredentials).toEqual(false);

expect(httpProvider.providersModuleFactory).toEqual(providersModuleFactoryMock);

expect(httpProvider.agent.httpAgent).toBeInstanceOf(http.Agent);
Expand Down Expand Up @@ -110,7 +138,8 @@ describe('HttpProviderTest', () => {
httpProvider.host,
httpProvider.timeout,
httpProvider.headers,
httpProvider.agent
httpProvider.agent,
httpProvider.withCredentials,
);

expect(xhrMock.send).toHaveBeenCalledWith('{"id":"0x0"}');
Expand Down Expand Up @@ -148,7 +177,8 @@ describe('HttpProviderTest', () => {
httpProvider.host,
httpProvider.timeout,
httpProvider.headers,
httpProvider.agent
httpProvider.agent,
httpProvider.withCredentials
);

expect(xhrMock.send).toHaveBeenCalledWith('{"id":"0x0"}');
Expand Down Expand Up @@ -189,7 +219,8 @@ describe('HttpProviderTest', () => {
httpProvider.host,
httpProvider.timeout,
httpProvider.headers,
httpProvider.agent
httpProvider.agent,
httpProvider.withCredentials
);

expect(xhrMock.send).toHaveBeenCalledWith('[{"id":"0x0"}]');
Expand Down Expand Up @@ -219,7 +250,8 @@ describe('HttpProviderTest', () => {
httpProvider.host,
httpProvider.timeout,
httpProvider.headers,
httpProvider.agent
httpProvider.agent,
httpProvider.withCredentials
);

expect(xhrMock.send).toHaveBeenCalledWith('{"id":"0x0"}');
Expand Down Expand Up @@ -247,7 +279,8 @@ describe('HttpProviderTest', () => {
httpProvider.host,
httpProvider.timeout,
httpProvider.headers,
httpProvider.agent
httpProvider.agent,
httpProvider.withCredentials
);

expect(xhrMock.send).toHaveBeenCalledWith('{"id":"0x0"}');
Expand All @@ -273,7 +306,8 @@ describe('HttpProviderTest', () => {
httpProvider.host,
httpProvider.timeout,
httpProvider.headers,
httpProvider.agent
httpProvider.agent,
httpProvider.withCredentials
);

expect(xhrMock.send).toHaveBeenCalledWith('{"id":"0x0"}');
Expand All @@ -297,7 +331,8 @@ describe('HttpProviderTest', () => {
httpProvider.host,
httpProvider.timeout,
httpProvider.headers,
httpProvider.agent
httpProvider.agent,
httpProvider.withCredentials
);

expect(xhrMock.send).toHaveBeenCalledWith('{"id":"0x0"}');
Expand Down
1 change: 1 addition & 0 deletions packages/web3-providers/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export interface HttpProviderOptions {
host?: string;
timeout?: number;
headers?: {};
withCredentials?: boolean;
}

export interface WebsocketProviderOptions {
Expand Down
3 changes: 2 additions & 1 deletion packages/web3-providers/types/tests/http-provider-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const httpProvider = new HttpProvider('http://localhost:8545', {
name: 'Access-Control-Allow-Origin',
value: '*'
}
]
],
withCredentials: false
});

// $ExpectType Promise<any>
Expand Down

0 comments on commit 169fceb

Please sign in to comment.