Commit 2fde53da by Rob Holland

Setup Enrichment.Company and Enrichment.Person correctly.

Add test coverage.
parent 39b31707
......@@ -16,9 +16,9 @@ function ClearbitClient (config) {
this.key = config.key || process.env.CLEARBIT_KEY;
assert(!!this.key, 'An API key must be provided');
this.Enrichment = require('./enrichment').Enrichment(this);
this.Company = require('./enrichment/company').Company(this);
this.Person = require('./enrichment/person').Person(this);
this.Enrichment = require('./enrichment').Enrichment(this);
this.Discovery = require('./discovery').Discovery(this);
this.Prospector = require('./prospector').Prospector(this);
this.Watchlist = require('./watchlist').Watchlist(this);
......
......@@ -2,22 +2,22 @@
var assert = require('assert');
var resource = require('./resource');
var Company = require('./enrichment/company');
var Person = require('./enrichment/person');
exports.Enrichment = resource.create('Enrichment', {api: 'person', version: 2})
exports.Enrichment = function(client) {
return resource.create('Enrichment', {api: 'person', version: 2})
.extend(null, {
find: function(options){
options = options || {};
if (options.domain)
return Company.find(options);
return client.Company.find(options);
assert(options.email, 'An email must be provided');
return this.get('/combined/find', options);
},
Company: Company,
Person: Person
});
Company: client.Company,
Person: client.Person
})(client);
};
'use strict';
var expect = require('chai').use(require('chai-as-promised')).expect;
var nock = require('nock');
var Enrichment = require('../')('k').Enrichment;
describe('Enrichment', function () {
var person_mock, company_mock;
before(function () {
person_mock = nock('https://person.clearbit.com');
company_mock = nock('https://company.clearbit.com');
});
after(nock.cleanAll);
afterEach(function () {
person_mock.done();
company_mock.done();
});
var alex = require('./fixtures/person');
var company = require('./fixtures/company');
describe('Enrichment#find', function () {
it('can find a person by email', function () {
person_mock
.get('/v2/combined/find?email=alex%40alexmaccaw.com')
.reply(200, {
person: alex,
company: company
});
return Enrichment.find({email: 'alex@alexmaccaw.com'})
.then(function (personCompany) {
expect(personCompany)
.to.be.an.instanceOf(Enrichment)
.and.have.include.keys('person', 'company')
.and.have.deep.property('person.id', alex.id);
});
});
it('can find a company by domain', function () {
company_mock
.get('/v2/companies/find?domain=uber.com')
.reply(200, company);
return Enrichment.find({domain: 'uber.com'})
.then(function (company) {
expect(company)
.to.be.an.instanceOf(Enrichment.Company)
.and.have.property('id', company.id);
});
});
it('can handle queued requests', function () {
person_mock
.get('/v2/combined/find?email=alex%40alexmaccaw.com')
.reply(202, {
error: {
type: 'queued'
}
});
return expect(Enrichment.find({email: 'alex@alexmaccaw.com'}))
.to.be.rejectedWith(Enrichment.QueuedError);
});
});
});
......@@ -3,7 +3,6 @@
var expect = require('chai').use(require('chai-as-promised')).expect;
var nock = require('nock');
var Person = require('../')('k').Person;
var Enrichment = require('../')('k').Enrichment;
describe('Person', function () {
......@@ -17,7 +16,6 @@ describe('Person', function () {
});
var alex = require('./fixtures/person');
var company = require('./fixtures/company');
describe('Person#find', function () {
......@@ -65,37 +63,4 @@ describe('Person', function () {
});
});
describe('Enrichment#find', function () {
it('can find a person by email', function () {
mock
.get('/v2/combined/find?email=alex%40alexmaccaw.com')
.reply(200, {
person: alex,
company: company
});
return Enrichment.find({email: 'alex@alexmaccaw.com'})
.then(function (personCompany) {
expect(personCompany)
.to.be.an.instanceOf(Enrichment)
.and.have.include.keys('person', 'company')
.and.have.deep.property('person.id', alex.id);
});
});
it('can handle queued requests', function () {
mock
.get('/v2/combined/find?email=alex%40alexmaccaw.com')
.reply(202, {
error: {
type: 'queued'
}
});
return expect(Enrichment.find({email: 'alex@alexmaccaw.com'}))
.to.be.rejectedWith(Enrichment.QueuedError);
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment