Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move from blanket+mocha to jest (#206)
- Use jest as the test runner - Remove should - Remove grunt
- Loading branch information
Showing
21 changed files
with
4,599 additions
and
2,693 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
/node_modules | ||
coverage.html | ||
node_modules | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/node_modules | ||
__mocks__ | ||
__tests__ | ||
node_modules | ||
.coveralls.yml | ||
.npmignore | ||
*.log | ||
/test | ||
Gruntfile.js | ||
.npmignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,5 @@ node_js: | |
- 'node' | ||
- '7' | ||
- '6' | ||
- '5.11' | ||
after_success: | ||
- npm run coveralls | ||
- npm run travis |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
'use strict'; | ||
|
||
//mock for superagent - __mocks__/superagent.js | ||
|
||
var mockDelay; | ||
var mockError; | ||
var mockResponse = { | ||
status() { | ||
return 200; | ||
}, | ||
ok() { | ||
return true; | ||
}, | ||
get: jest.genMockFunction(), | ||
toError: jest.genMockFunction() | ||
}; | ||
|
||
var Request = { | ||
put() { | ||
return this; | ||
}, | ||
del() { | ||
return this; | ||
}, | ||
post() { | ||
return this; | ||
}, | ||
get() { | ||
return this; | ||
}, | ||
send() { | ||
return this; | ||
}, | ||
query() { | ||
return this; | ||
}, | ||
field() { | ||
return this; | ||
}, | ||
set() { | ||
return this; | ||
}, | ||
accept() { | ||
return this; | ||
}, | ||
timeout() { | ||
return this; | ||
}, | ||
end: jest.genMockFunction().mockImplementation(function(callback) { | ||
if (mockDelay) { | ||
this.delayTimer = setTimeout(callback, 0, mockError, mockResponse); | ||
return; | ||
} | ||
|
||
callback(mockError, mockResponse); | ||
}), | ||
//expose helper methods for tests to set | ||
__setMockDelay(boolValue) { | ||
mockDelay = boolValue; | ||
}, | ||
__setMockResponse(mockRes) { | ||
mockResponse = mockRes; | ||
}, | ||
__setMockError(mockErr) { | ||
mockError = mockErr; | ||
}, | ||
__reset() { | ||
this.__setMockResponse({ | ||
status() { | ||
return 200; | ||
}, | ||
ok() { | ||
return true; | ||
} | ||
}); | ||
this.__setMockError(null); | ||
this.__setMockDelay(false); | ||
} | ||
}; | ||
|
||
module.exports = Request; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
var AuthenticationRequest = require('../src/authentication-request'); | ||
|
||
describe('Create Authentication Requests', () => { | ||
test('Should use default settings if none are supplied', () => { | ||
var request = AuthenticationRequest.builder().build(); | ||
|
||
expect(request.getHost()).toBe('accounts.spotify.com'); | ||
expect(request.getPort()).toBe(443); | ||
expect(request.getScheme()).toBe('https'); | ||
expect(request.getHeaders()).toBeFalsy(); | ||
expect(request.getPath()).toBeFalsy(); | ||
expect(request.getQueryParameters()).toBeFalsy(); | ||
expect(request.getBodyParameters()).toBeFalsy(); | ||
}); | ||
|
||
test('Can overwrite one of the default parameters', () => { | ||
var request = AuthenticationRequest.builder() | ||
.withHost('such.host.wow') | ||
.build(); | ||
|
||
expect(request.getHost()).toBe('such.host.wow'); | ||
expect(request.getPort()).toBe(443); | ||
expect(request.getScheme()).toBe('https'); | ||
expect(request.getHeaders()).toBeFalsy(); | ||
expect(request.getPath()).toBeFalsy(); | ||
expect(request.getQueryParameters()).toBeFalsy(); | ||
expect(request.getBodyParameters()).toBeFalsy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
var Request = require('../src/base-request'); | ||
|
||
describe('Create Requests', () => { | ||
test('Should create host, port, and scheme', () => { | ||
var request = Request.builder() | ||
.withHost('such.api.wow') | ||
.withPort(1337) | ||
.withScheme('http') | ||
.build(); | ||
|
||
expect(request.getHost()).toBe('such.api.wow'); | ||
expect(request.getPort()).toBe(1337); | ||
expect(request.getScheme()).toBe('http'); | ||
}); | ||
|
||
test('Should add query parameters', () => { | ||
var request = Request.builder() | ||
.withHost('such.api.wow') | ||
.withPort(1337) | ||
.withScheme('http') | ||
.withQueryParameters({ | ||
oneParameter: 1, | ||
anotherParameter: true, | ||
thirdParameter: 'hello' | ||
}) | ||
.build(); | ||
|
||
expect(request.getQueryParameters().oneParameter).toBe(1); | ||
expect(request.getQueryParameters().anotherParameter).toBe(true); | ||
expect(request.getQueryParameters().thirdParameter).toBe('hello'); | ||
}); | ||
|
||
test('Should add query parameters (multiple calls)', () => { | ||
var request = Request.builder() | ||
.withHost('such.api.wow') | ||
.withPort(1337) | ||
.withScheme('http') | ||
.withQueryParameters({ | ||
oneParameter: 1, | ||
anotherParameter: true | ||
}) | ||
.withQueryParameters({ | ||
thirdParameter: 'hello' | ||
}) | ||
.build(); | ||
|
||
expect(request.getQueryParameters().oneParameter).toBe(1); | ||
expect(request.getQueryParameters().anotherParameter).toBe(true); | ||
expect(request.getQueryParameters().thirdParameter).toBe('hello'); | ||
}); | ||
|
||
test('Should add query parameters (combine calls)', () => { | ||
var request = Request.builder() | ||
.withHost('such.api.wow') | ||
.withPort(1337) | ||
.withScheme('http') | ||
.withQueryParameters( | ||
{ | ||
oneParameter: 1, | ||
anotherParameter: true | ||
}, | ||
{ | ||
thirdParameter: 'hello' | ||
} | ||
) | ||
.build(); | ||
|
||
expect(request.getQueryParameters().oneParameter).toBe(1); | ||
expect(request.getQueryParameters().anotherParameter).toBe(true); | ||
expect(request.getQueryParameters().thirdParameter).toBe('hello'); | ||
}); | ||
|
||
test('Should add body parameters', () => { | ||
var request = Request.builder() | ||
.withHost('such.api.wow') | ||
.withPort(1337) | ||
.withScheme('http') | ||
.withBodyParameters({ | ||
one: 1, | ||
two: true, | ||
three: 'world' | ||
}) | ||
.build(); | ||
|
||
expect(request.getBodyParameters().one).toBe(1); | ||
expect(request.getBodyParameters().two).toBe(true); | ||
expect(request.getBodyParameters().three).toBe('world'); | ||
}); | ||
|
||
test('Should add array to body parameters', () => { | ||
var request = Request.builder() | ||
.withHost('such.api.wow') | ||
.withPort(1337) | ||
.withScheme('http') | ||
.withBodyParameters(['3VNWq8rTnQG6fM1eldSpZ0']) | ||
.build(); | ||
|
||
expect(request.getBodyParameters()).toEqual(['3VNWq8rTnQG6fM1eldSpZ0']); | ||
}); | ||
|
||
test('Should add header parameters', () => { | ||
var request = Request.builder() | ||
.withHost('such.api.wow') | ||
.withPort(1337) | ||
.withScheme('http') | ||
.withHeaders({ | ||
Authorization: 'Basic WOOP', | ||
'Content-Type': 'application/lol' | ||
}) | ||
.build(); | ||
|
||
expect(request.getHeaders().Authorization).toBe('Basic WOOP'); | ||
expect(request.getHeaders()['Content-Type']).toBe('application/lol'); | ||
}); | ||
|
||
test('Should add path', () => { | ||
var request = Request.builder() | ||
.withHost('such.api.wow') | ||
.withPort(1337) | ||
.withPath('/v1/users/meriosweg') | ||
.build(); | ||
|
||
expect(request.getPath()).toBe('/v1/users/meriosweg'); | ||
}); | ||
|
||
test('Should build URI', () => { | ||
var request = Request.builder() | ||
.withHost('such.api.wow') | ||
.withScheme('https') | ||
.withPort(1337) | ||
.withPath('/v1/users/meriosweg') | ||
.build(); | ||
|
||
expect(request.getURI()).toBe( | ||
'https://such.api.wow:1337/v1/users/meriosweg' | ||
); | ||
}); | ||
|
||
test('Should construct empty query paramaters string', () => { | ||
var request = Request.builder() | ||
.withQueryParameters({}) | ||
.build(); | ||
|
||
expect(request.getQueryParameterString()).toBeFalsy(); | ||
}); | ||
|
||
test('Should construct query paramaters string for one parameter', () => { | ||
var request = Request.builder() | ||
.withQueryParameters({ | ||
one: 1 | ||
}) | ||
.build(); | ||
|
||
expect(request.getQueryParameterString()).toBe('?one=1'); | ||
}); | ||
|
||
test('Should construct query paramaters string for multiple parameters', () => { | ||
var request = Request.builder() | ||
.withQueryParameters({ | ||
one: 1, | ||
two: true, | ||
three: 'world' | ||
}) | ||
.build(); | ||
|
||
expect(request.getQueryParameterString()).toBe( | ||
'?one=1&two=true&three=world' | ||
); | ||
}); | ||
|
||
test('Should construct query paramaters string and exclude undefined values', () => { | ||
var request = Request.builder() | ||
.withQueryParameters({ | ||
one: 1, | ||
two: undefined, | ||
three: 'world' | ||
}) | ||
.build(); | ||
|
||
expect(request.getQueryParameterString()).toBe('?one=1&three=world'); | ||
}); | ||
}); |
Oops, something went wrong.