Skip to content

Commit

Permalink
Merge pull request #5 from tchaffee/feat/update_password
Browse files Browse the repository at this point in the history
feat: add Sift $update_password event.
  • Loading branch information
officert authored Mar 31, 2020
2 parents 0ce8021 + 5dc50ed commit a258fca
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ client.events.updateAccount({
});
```

### [Update Password](https://sift.com/developers/docs/curl/events-api/reserved-events/update-password)

```javascript
client.events.updatePassword({
$user_id : '123',
$session_id: 'gigtleqddo84l8cm15qe4il'
});
```

### [Create Content](https://siftscience.com/developers/docs/curl/events-api/reserved-events/create-content)

```javascript
Expand Down
14 changes: 14 additions & 0 deletions lib/client/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ function getEventsApi(siftScienceClient) {

return this.create(data, params);
},
/**
* @param {Object} [data]
* @param {Object} [params]
* https://sift.com/developers/docs/curl/events-api/reserved-events/update-password
*/
updatePassword(data = {}, params = {}) {
const event = '$update_password';

_.extend(data, {
$type: event
});

return this.create(data, params);
},
/**
* @param {Object} [data]
* @param {Object} [params]
Expand Down
93 changes: 93 additions & 0 deletions tests/lib/client/events/updatePassword.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
const should = require('should');
const Promise = require('bluebird');
const sinon = require('sinon');
const _ = require('lodash');

let SiftScienceClient;
let v205HttpClient;
let sandbox;

before(() => {
SiftScienceClient = require('../../../../lib');
v205HttpClient = require('../../../../lib/client/v205HttpClient');

sandbox = sinon.sandbox.create();
});

describe('lib', () => {
describe('client', () => {
describe('events', () => {
describe('updatePassword', () => {
afterEach(() => {
sandbox.restore();
});

const key = '123';
let siftScienceClient;

before('create siftScienceClient', () => {
siftScienceClient = new SiftScienceClient(key);
});

describe('when called with nothing', () => {
let postStub;

let response = {
data: {}
};

before('stub v205HttpClient.post()', () => {
postStub = sandbox.stub(v205HttpClient, 'post')
.returns(Promise.resolve(response));
});

it('should call v205HttpClient.post()', () => {
return siftScienceClient.events.updatePassword()
.then(result => {
should.exist(result);
result.should.deepEqual(response.data);

postStub.callCount.should.equal(1);
postStub.args[0][0].should.equal('/events');
postStub.args[0][1].should.deepEqual({
$type: '$update_password',
$api_key: key
});
});
});
});

describe('when called with data', () => {
let data = {
foo: 'bar'
};
let postStub;

let response = {
data: {}
};

before('stub v205HttpClient.post()', () => {
postStub = sandbox.stub(v205HttpClient, 'post')
.returns(Promise.resolve(response));
});

it('should call v205HttpClient.post()', () => {
return siftScienceClient.events.updatePassword(data)
.then(result => {
should.exist(result);
result.should.deepEqual(response.data);

postStub.callCount.should.equal(1);
postStub.args[0][0].should.equal('/events');
postStub.args[0][1].should.deepEqual(_.extend(data, {
$type: '$update_password',
$api_key: key
}));
});
});
});
});
});
});
});

0 comments on commit a258fca

Please sign in to comment.