-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from Hacksore/develop
Develop
- Loading branch information
Showing
35 changed files
with
8,021 additions
and
3,009 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 |
---|---|---|
|
@@ -21,3 +21,4 @@ jobs: | |
# run tests! | ||
- run: yarn lint | ||
- run: yarn build | ||
- run: yarn test --verbose |
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 |
---|---|---|
|
@@ -12,5 +12,5 @@ module.exports = { | |
env: { | ||
browser: true, | ||
node: true, | ||
}, | ||
} | ||
}; |
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 |
---|---|---|
|
@@ -4,3 +4,6 @@ node_modules/ | |
.rpt2_cache | ||
dist/ | ||
config*.json | ||
.vs/ | ||
.vscode/ | ||
coverage/ |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
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,67 @@ | ||
|
||
/* eslint-disable */ | ||
|
||
import got from 'got'; | ||
import BlueLinky from '../lib/index'; | ||
jest.mock('got'); | ||
|
||
describe('BlueLinky', () => { | ||
|
||
beforeEach(() => { | ||
(got as any).mockReturnValueOnce({ | ||
body: { | ||
'access_token': 'test', | ||
'refresh_token': 'test', | ||
'expires_in': 'test' | ||
}, | ||
statusCode: 200 | ||
}) | ||
.mockReturnValueOnce({ | ||
body: '[]', | ||
statusCode: 200 | ||
}); | ||
}); | ||
|
||
it('creates a client with valid config', () => { | ||
const client = new BlueLinky({ | ||
username: '[email protected]', | ||
password: 'hunter1', | ||
pin: '1234', | ||
region: 'US' | ||
}); | ||
|
||
expect(client).toBeDefined(); | ||
|
||
client.on('ready', () => { | ||
expect(client.getSession()).toBeDefined(); | ||
expect(client.getSession().accessToken).toEqual('test'); | ||
}); | ||
|
||
}); | ||
|
||
it('throws error when you pass invalid region', () => { | ||
expect(() => { | ||
const client = new BlueLinky({ | ||
username: '[email protected]', | ||
password: 'hunter1', | ||
pin: '1234', | ||
region: 'KR' | ||
}) | ||
}).toThrowError('Your region is not supported yet.'); | ||
}); | ||
|
||
it('ready event is called after login', (done) => { | ||
const client = new BlueLinky({ | ||
username: '[email protected]', | ||
password: 'hunter1', | ||
pin: '1234', | ||
region: 'US' | ||
}); | ||
|
||
client.on('ready', () => { | ||
done(); | ||
}); | ||
|
||
}); | ||
|
||
}); |
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,134 @@ | ||
/* eslint-disable */ | ||
import got from 'got'; | ||
|
||
import { AmericanController } from '../lib/controllers/american.controller'; | ||
import { EuropeanController } from '../lib/controllers/european.controller'; | ||
import { CanadianController } from '../lib/controllers/canadian.controller'; | ||
|
||
jest.mock('got'); | ||
|
||
const getController = region => { | ||
const referenceMap = { | ||
US: AmericanController, | ||
EU: EuropeanController, | ||
CA: CanadianController, | ||
}; | ||
|
||
const controller = new referenceMap[region]({ | ||
username: '[email protected]', | ||
password: 'test', | ||
region: 'US', | ||
autoLogin: true, | ||
pin: '1234', | ||
vin: '4444444444444', | ||
vehicleId: undefined, | ||
deviceUuid: '', | ||
}); | ||
|
||
return controller; | ||
}; | ||
|
||
describe('AmericanController', () => { | ||
it('call getVehicles and check length', async () => { | ||
const controller = getController('US'); | ||
|
||
(got as any).mockReturnValueOnce({ | ||
body: JSON.stringify({ | ||
enrolledVehicleDetails: [ | ||
{ | ||
vehicleDetails: [ | ||
{ | ||
nickname: 'Jest is best', | ||
vin: '444', | ||
regDate: 'test', | ||
brandIndicator: 'H', | ||
regId: '123123', | ||
gen: '2', | ||
name: 'Car', | ||
}, | ||
], | ||
}, | ||
], | ||
}), | ||
statusCode: 200, | ||
}); | ||
|
||
expect(await controller.getVehicles()).toHaveLength(1); | ||
}); | ||
}); | ||
|
||
describe('EuropeanController', () => { | ||
|
||
it('call getVehicles and check length', async () => { | ||
const controller = getController('EU'); | ||
|
||
(got as any).mockReturnValueOnce({ | ||
body: { | ||
resMsg: { | ||
vehicles: [ | ||
{ | ||
nickname: 'Jest is best', | ||
vin: '444', | ||
regDate: 'test', | ||
brandIndicator: 'H', | ||
regId: '123123', | ||
gen: '2', | ||
name: 'Car', | ||
}, | ||
], | ||
}, | ||
}, | ||
statusCode: 200, | ||
}); | ||
|
||
(got as any).mockReturnValueOnce({ | ||
body: { | ||
resMsg: { | ||
vinInfo: [ | ||
{ | ||
basic: { | ||
modelYear: '2019', | ||
vin: '5555' | ||
} | ||
} | ||
], | ||
}, | ||
}, | ||
statusCode: 200, | ||
}); | ||
|
||
const vehicles = await controller.getVehicles(); | ||
expect(vehicles).toHaveLength(1); | ||
}); | ||
}); | ||
|
||
describe('CanadianController', () => { | ||
|
||
it('call getVehicles and check length', async () => { | ||
const controller = getController('CA'); | ||
|
||
(got as any).mockReturnValueOnce({ | ||
body: { | ||
responseHeader: { | ||
responseCode: 0, | ||
}, | ||
result: { | ||
vehicles: [ | ||
{ | ||
nickname: 'Jest is best', | ||
vin: '444', | ||
regDate: 'test', | ||
brandIndicator: 'H', | ||
regId: '123123', | ||
gen: '2', | ||
name: 'Car', | ||
}, | ||
], | ||
}, | ||
}, | ||
statusCode: 200, | ||
}); | ||
|
||
expect(await controller.getVehicles()).toHaveLength(1); | ||
}); | ||
}); |
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,137 @@ | ||
/* eslint-disable */ | ||
import got from 'got'; | ||
|
||
import AmericanVehicle from '../lib/vehicles/americanVehicle'; | ||
import { AmericanController } from '../lib/controllers/american.controller'; | ||
|
||
import EuropeanVehicle from '../lib/vehicles/europianVehicle'; | ||
import { EuropeanController } from '../lib/controllers/european.controller'; | ||
|
||
import CanadianVehicle from '../lib/vehicles/canadianVehicle'; | ||
import { CanadianController } from '../lib/controllers/canadian.controller'; | ||
|
||
jest.mock('got'); | ||
|
||
const getVehicle = region => { | ||
const referenceMap = { | ||
US: { | ||
controller: AmericanController, | ||
vehicle: AmericanVehicle, | ||
}, | ||
EU: { | ||
controller: EuropeanController, | ||
vehicle: EuropeanVehicle, | ||
}, | ||
CA: { | ||
controller: CanadianController, | ||
vehicle: CanadianVehicle, | ||
}, | ||
}; | ||
|
||
const controller = new referenceMap[region].controller({ | ||
username: '[email protected]', | ||
password: 'test', | ||
region: 'US', | ||
autoLogin: true, | ||
pin: '1234', | ||
vin: '4444444444444', | ||
vehicleId: undefined, | ||
deviceUuid: '', | ||
}); | ||
|
||
const vehicle = new referenceMap[region].vehicle( | ||
{ | ||
nickname: 'Jest is best', | ||
vin: '444', | ||
regDate: 'test', | ||
brandIndicator: 'H', | ||
regId: '123123', | ||
gen: '2', | ||
name: 'Car', | ||
}, | ||
controller | ||
); | ||
|
||
return vehicle; | ||
}; | ||
|
||
describe('AmericanVehicle', () => { | ||
const vehicle = getVehicle('US'); | ||
|
||
it('define new vehicle', () => { | ||
expect(vehicle.config.nickname).toEqual('Jest is best'); | ||
}); | ||
|
||
it('call lock commmand', async () => { | ||
(got as any).mockReturnValueOnce({ | ||
body: {}, | ||
statusCode: 200, | ||
}); | ||
|
||
const response = await vehicle.lock(); | ||
expect(response).toEqual('Lock successful'); | ||
|
||
}); | ||
}); | ||
|
||
describe('CanadianVehicle', () => { | ||
const vehicle = getVehicle('CA'); | ||
|
||
it('define new vehicle', () => { | ||
expect(vehicle.config.nickname).toEqual('Jest is best'); | ||
}); | ||
|
||
it('call lock commmand', async () => { | ||
(got as any).mockReturnValueOnce({ | ||
body: { | ||
result: { | ||
pAuth: 'test' | ||
}, | ||
responseHeader: { | ||
responseCode: 0, | ||
}, | ||
}, | ||
statusCode: 200, | ||
}); | ||
|
||
(got as any).mockReturnValueOnce({ | ||
body: { | ||
responseHeader: { | ||
responseCode: 0, | ||
}, | ||
}, | ||
statusCode: 200, | ||
}); | ||
|
||
const response = await vehicle.lock(); | ||
expect(response).toEqual('Lock successful'); | ||
}); | ||
}); | ||
|
||
describe('EuropeanVehicle', () => { | ||
const vehicle = getVehicle('EU'); | ||
|
||
it('define new vehicle', () => { | ||
expect(vehicle.config.nickname).toEqual('Jest is best'); | ||
}); | ||
|
||
it('call lock commmand', async () => { | ||
(got as any).mockReturnValueOnce({ | ||
body: {}, | ||
statusCode: 200 | ||
}); | ||
|
||
const response = await vehicle.lock(); | ||
expect(response).toEqual('Lock successful'); | ||
}); | ||
|
||
it('call unlock commmand', async () => { | ||
(got as any).mockReturnValueOnce({ | ||
body: {}, | ||
statusCode: 200 | ||
}); | ||
|
||
const response = await vehicle.unlock(); | ||
expect(response).toEqual('Unlock successful'); | ||
}); | ||
}); |
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,6 @@ | ||
module.exports = { | ||
presets: [ | ||
['@babel/preset-env', {targets: {node: 'current'}}], | ||
'@babel/preset-typescript', | ||
], | ||
}; |
Oops, something went wrong.