Skip to content

Commit

Permalink
fix: tests for compatibility v2 (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ashwinkumar authored Jul 27, 2021
1 parent f740585 commit aba91fe
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 30 deletions.
3 changes: 2 additions & 1 deletion lib/auth-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ function AuthClient(options = {}) {
|| util.getOrThrowConfig('SMARTCAR_REDIRECT_URI');

this.testMode = options.testMode === true;
this.authUrl = util.getConfig('SMARTCAR_AUTH_ORIGIN') || config.auth;

this.service = new SmartcarService({
baseUrl: util.getConfig('SMARTCAR_AUTH_ORIGIN') || config.auth,
baseUrl: this.authUrl,
auth: {
user: this.clientId,
pass: this.clientSecret,
Expand Down
3 changes: 2 additions & 1 deletion test/end-to-end/auth-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ test('exchangeRefreshToken', async(t) => {
const error = await t.throwsAsync(
client.exchangeRefreshToken(oldAccess.refreshToken)
);
const expectedMessage = 'invalid_grant:undefined - Invalid or expired refresh token.';
const expectedMessage =
'invalid_grant:undefined - Invalid or expired refresh token.';
t.is(error.message, expectedMessage);

t.is(error.type, 'invalid_grant');
Expand Down
37 changes: 16 additions & 21 deletions test/end-to-end/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,20 @@ test('getCompatibility', async(t) => {
null,
{clientId, clientSecret},
);

t.deepEqual(
_.xor(_.keys(teslaComp), [
'compatible',
'meta',
]),
[],
);

t.deepEqual(
_.xor(_.keys(audiComp), [
'compatible',
'meta',
]),
[],
);

t.truthy(teslaComp.compatible);
t.deepEqual(teslaComp.meta.requestId.length, 36);
t.falsy(audiComp.compatible);
t.deepEqual(audiComp.meta.requestId.length, 36);
[teslaComp, audiComp].forEach((response) => {
t.deepEqual(
_.xor(_.keys(response), [
'compatible',
'reason',
'capabilities',
'meta',
]),
[],
);
t.truthy(response.compatible);
t.deepEqual(response.meta.requestId.length, 36);
t.deepEqual(response.capabilities.length, 2);
});
t.truthy(_.every(audiComp.capabilities, ['capable', false]));
t.truthy(_.every(teslaComp.capabilities, ['capable', true]));
});
14 changes: 7 additions & 7 deletions test/end-to-end/vehicle.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ const getVehicle = async function(brand, scope) {
};

test.before(async(t) => {
const [volt, egolf] = await Promise.all([
const [volt, tesla] = await Promise.all([
getVehicle('CHEVROLET', DEFAULT_SCOPES),
getVehicle('VOLKSWAGEN', [
getVehicle('TESLA', [
'required:control_charge',
'required:control_security',
]),
]);

smartcar.setApiVersion('1.0');
t.context = {volt, egolf};
t.context = {volt, tesla};
});

test('vehicle vin', async(t) => {
Expand Down Expand Up @@ -278,7 +278,7 @@ test('vehicle unsubscribe - error', async(t) => {
});

test('vehicle lock', async(t) => {
const response = await t.context.egolf.lock();
const response = await t.context.tesla.lock();
t.deepEqual(
_.xor(_.keys(response), [
'status',
Expand All @@ -294,7 +294,7 @@ test('vehicle lock', async(t) => {
});

test('vehicle unlock', async(t) => {
const response = await t.context.egolf.unlock();
const response = await t.context.tesla.unlock();
t.deepEqual(
_.xor(_.keys(response), [
'status',
Expand All @@ -310,7 +310,7 @@ test('vehicle unlock', async(t) => {
});

test('vehicle startCharge', async(t) => {
const response = await t.context.egolf.startCharge();
const response = await t.context.tesla.startCharge();
t.deepEqual(
_.xor(_.keys(response), [
'status',
Expand All @@ -326,7 +326,7 @@ test('vehicle startCharge', async(t) => {
});

test('vehicle stopCharge', async(t) => {
const response = await t.context.egolf.stopCharge();
const response = await t.context.tesla.stopCharge();
t.deepEqual(
_.xor(_.keys(response), [
'status',
Expand Down

0 comments on commit aba91fe

Please sign in to comment.