-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
299 additions
and
0 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
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,36 @@ | ||
const Promise = require('bluebird'); | ||
const v204 = require('./v204'); | ||
const _ = require('lodash'); | ||
|
||
function getLabelsApi(key) { | ||
return { | ||
/** | ||
* @param {Object} [data] | ||
* https://siftscience.com/developers/docs/curl/labels-api/label-user | ||
*/ | ||
createByUserId(userId, data = {}) { | ||
if (!userId) return Promise.reject(new Error('userId is required')); | ||
|
||
_.extend(data, { | ||
$api_key: key | ||
}); | ||
|
||
return v204.post(`/users/${userId}/labels`, data); | ||
}, | ||
/** | ||
* @param {Object} [data] | ||
* https://siftscience.com/developers/docs/curl/labels-api/unlabel-user | ||
*/ | ||
deleteByUserId(userId, data = {}) { | ||
if (!userId) return Promise.reject(new Error('userId is required')); | ||
|
||
_.extend(data, { | ||
$api_key: key | ||
}); | ||
|
||
return v204.delete(`/users/${userId}/labels`, data); | ||
} | ||
}; | ||
} | ||
|
||
module.exports = getLabelsApi; |
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,73 @@ | ||
const should = require('should'); | ||
const sinon = require('sinon'); | ||
|
||
let siftScience; | ||
let v204; | ||
let sandbox; | ||
|
||
before(() => { | ||
siftScience = require('lib'); | ||
v204 = require('lib/client/v204'); | ||
|
||
sandbox = sinon.sandbox.create(); | ||
}); | ||
|
||
describe('siftScience', () => { | ||
describe('client', () => { | ||
describe('labels', () => { | ||
describe('createByUserId', () => { | ||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
const key = '123'; | ||
let siftScienceClient; | ||
|
||
before('create siftScienceClient', () => { | ||
siftScienceClient = siftScience.init(key); | ||
}); | ||
|
||
describe('when called without userId', () => { | ||
let userId = null; | ||
|
||
it('should reject with an error', () => { | ||
return siftScienceClient.labels.createByUserId(userId) | ||
.then(should.not.exist) | ||
.catch(err => { | ||
should.exist(err); | ||
err.should.be.instanceOf(Error); | ||
err.message.should.equal('userId is required'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when called with a userId', () => { | ||
let userId = '123'; | ||
let params = { | ||
foo: 'bar' | ||
}; | ||
let expectedResponse = {}; | ||
|
||
let postStub; | ||
|
||
before('stub v204._client.post()', () => { | ||
postStub = sandbox.stub(v204._client, 'post') | ||
.returns(Promise.resolve(expectedResponse)); | ||
}); | ||
|
||
it('should call v204._client.post()', () => { | ||
return siftScienceClient.labels.createByUserId(userId, params) | ||
.then(response => { | ||
should.exist(response); | ||
response.should.deepEqual(expectedResponse); | ||
|
||
postStub.callCount.should.equal(1); | ||
postStub.args[0][0].should.equal(`/users/${userId}/labels`); | ||
postStub.args[0][1].should.deepEqual(params); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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,75 @@ | ||
const should = require('should'); | ||
const sinon = require('sinon'); | ||
|
||
let siftScience; | ||
let v204; | ||
let sandbox; | ||
|
||
before(() => { | ||
siftScience = require('lib'); | ||
v204 = require('lib/client/v204'); | ||
|
||
sandbox = sinon.sandbox.create(); | ||
}); | ||
|
||
describe('siftScience', () => { | ||
describe('client', () => { | ||
describe('labels', () => { | ||
describe('deleteByUserId', () => { | ||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
const key = '123'; | ||
let siftScienceClient; | ||
|
||
before('create siftScienceClient', () => { | ||
siftScienceClient = siftScience.init(key); | ||
}); | ||
|
||
describe('when called without userId', () => { | ||
let userId = null; | ||
|
||
it('should reject with an error', () => { | ||
return siftScienceClient.labels.deleteByUserId(userId) | ||
.then(should.not.exist) | ||
.catch(err => { | ||
should.exist(err); | ||
err.should.be.instanceOf(Error); | ||
err.message.should.equal('userId is required'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when called with a userId', () => { | ||
let userId = '123'; | ||
let params = { | ||
foo: 'bar' | ||
}; | ||
let expectedResponse = {}; | ||
|
||
let deleteStub; | ||
|
||
before('stub v204._client.delete()', () => { | ||
deleteStub = sandbox.stub(v204._client, 'delete') | ||
.returns(Promise.resolve(expectedResponse)); | ||
}); | ||
|
||
it('should call v204._client.delete()', () => { | ||
return siftScienceClient.labels.deleteByUserId(userId, params) | ||
.then(response => { | ||
should.exist(response); | ||
response.should.deepEqual(expectedResponse); | ||
|
||
deleteStub.callCount.should.equal(1); | ||
deleteStub.args[0][0].should.equal(`/users/${userId}/labels`); | ||
deleteStub.args[0][1].should.deepEqual({ | ||
params | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
102 changes: 102 additions & 0 deletions
102
tests/siftScience/client/v204/httpClient/delete-test.js
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,102 @@ | ||
const should = require('should'); | ||
const Promise = require('bluebird'); | ||
const sinon = require('sinon'); | ||
|
||
let v204; | ||
let sandbox; | ||
|
||
before(() => { | ||
v204 = require('lib/client/v204'); | ||
|
||
sandbox = sinon.sandbox.create(); | ||
}); | ||
|
||
describe('siftScience', () => { | ||
describe('client', () => { | ||
describe('v204', () => { | ||
describe('httpClient', () => { | ||
describe('delete', () => { | ||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('when no path is passed', () => { | ||
let path = null; | ||
let expectedResponse = {}; | ||
|
||
let deleteStub; | ||
|
||
before('stub v204.delete()', () => { | ||
deleteStub = sandbox.stub(v204._client, 'delete') | ||
.returns(Promise.resolve(expectedResponse)); | ||
}); | ||
|
||
it('should reject with an error', () => { | ||
return v204.delete(path) | ||
.then(should.not.exist) | ||
.catch(err => { | ||
should.exist(err); | ||
err.should.be.instanceOf(Error); | ||
err.message.should.equal('path is required'); | ||
|
||
deleteStub.callCount.should.equal(0); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when a path is passed', () => { | ||
let path = '/foobar'; | ||
let expectedResponse = {}; | ||
|
||
let deleteStub; | ||
|
||
before('stub v204.delete()', () => { | ||
deleteStub = sandbox.stub(v204._client, 'delete') | ||
.returns(Promise.resolve(expectedResponse)); | ||
}); | ||
|
||
it('should resolve and call v204Client._client.delete()', () => { | ||
return v204.delete(path) | ||
.then(response => { | ||
should.exist(response); | ||
response.should.deepEqual(expectedResponse); | ||
|
||
deleteStub.callCount.should.equal(1); | ||
deleteStub.args[0][0].should.equal(path); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when params are passed', () => { | ||
let path = '/foobar'; | ||
let params = { | ||
query: 'string' | ||
}; | ||
let expectedResponse = {}; | ||
|
||
let deleteStub; | ||
|
||
before('stub v204.delete()', () => { | ||
deleteStub = sandbox.stub(v204._client, 'delete') | ||
.returns(Promise.resolve(expectedResponse)); | ||
}); | ||
|
||
it('should resolve and call v204Client._client.delete()', () => { | ||
return v204.delete(path, params) | ||
.then(response => { | ||
should.exist(response); | ||
response.should.deepEqual(expectedResponse); | ||
|
||
deleteStub.callCount.should.equal(1); | ||
deleteStub.args[0][0].should.equal(path); | ||
deleteStub.args[0][1].should.deepEqual({ | ||
params | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |