Skip to content

Commit

Permalink
feat: add compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Zhang authored Feb 26, 2019
1 parent 26e2756 commit 0571b97
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const client = new smartcar.AuthClient({
// Redirect to Smartcar's authentication flow
app.get('/login', function(req, res) {

const link = client.getAuthUrl({state: 'MY_STATE_PARAM'});
const link = client.getAuthUrl();

// redirect to the link
res.redirect(link);
Expand Down
14 changes: 14 additions & 0 deletions doc/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ Error thrown when gateway to Smartcar times out
* [.getAuthUrl([options])](#AuthClient+getAuthUrl) ⇒ <code>String</code>
* [.exchangeCode(code)](#AuthClient+exchangeCode)[<code>Promise.&lt;Access&gt;</code>](#Access)
* [.exchangeRefreshToken(token)](#AuthClient+exchangeRefreshToken)[<code>Promise.&lt;Access&gt;</code>](#Access)
* [.compatibility(vin)](#AuthClient+compatibility) ⇒ <code>Promise.&lt;Boolean&gt;</code>

<a name="new_AuthClient_new"></a>

Expand Down Expand Up @@ -372,6 +373,19 @@ Exchange a refresh token for a new access object.
| --- | --- | --- |
| token | <code>String</code> | Refresh token to exchange for a new set of Access and Refresh tokens. |

<a name="AuthClient+compatibility"></a>

### authClient.compatibility(vin) ⇒ <code>Promise.&lt;Boolean&gt;</code>
Determine whether a vehicle is compatible with Smartcar

**Kind**: instance method of [<code>AuthClient</code>](#AuthClient)
**Returns**: <code>Promise.&lt;Boolean&gt;</code> - true if the vehicle is compatible
with Smartcar

| Param | Type | Description |
| --- | --- | --- |
| vin | <code>String</code> | the VIN of the vehicle |

<a name="Vehicle"></a>

## Vehicle
Expand Down
21 changes: 21 additions & 0 deletions lib/auth-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,25 @@ AuthClient.prototype.exchangeRefreshToken = function(token) {

};

/**
* Determine whether a vehicle is compatible with Smartcar
*
* @param {String} vin - the VIN of the vehicle
* @return {Promise.<Boolean>} true if the vehicle is compatible
* with Smartcar
*/
AuthClient.prototype.compatibility = function(vin) {

const qs = {vin};

return util.wrap(this.request.get({
baseUrl: config.api,
url: `v${config.version}/compatibility`,
qs,
}))
.then(function(response) {
return response.compatible;
});
};

module.exports = AuthClient;
13 changes: 13 additions & 0 deletions test/end-to-end/auth-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,16 @@ test('exchangeRefreshToken', async(t) => {
'refreshToken',
]), []);
});

test('compatibility', async(t) => {
const client = new smartcar.AuthClient(getAuthClientParams());

const teslaVin = '5YJXCDE22HF068739';
const royceVin = 'SCA665C59HUX86700';

const teslaComp = await client.compatibility(teslaVin);
const royceComp = await client.compatibility(royceVin);

t.truthy(teslaComp);
t.falsy(royceComp);
});
26 changes: 26 additions & 0 deletions test/unit/lib/auth-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,29 @@ test('exchangeRefreshToken', async function(t) {
t.true(n.isDone());

});

test('compatibility', async function(t) {
const client = new AuthClient({
clientId: CLIENT_ID,
clientSecret: CLIENT_SECRET,
redirectUri: 'https://insurance.co/callback',
});

const vin = 'fake_vin';

const n = nock('https://api.smartcar.com')
.get('/v1.0/compatibility')
.query({vin})
.basicAuth({
user: CLIENT_ID,
pass: CLIENT_SECRET,
})
.reply(200, {
compatible: true,
});

const response = await client.compatibility(vin);

t.is(response, true);
t.true(n.isDone());
});

0 comments on commit 0571b97

Please sign in to comment.