Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
clearbit
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
prospector
clearbit
Commits
2fde53da
Commit
2fde53da
authored
Nov 17, 2015
by
Rob Holland
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Setup Enrichment.Company and Enrichment.Person correctly.
Add test coverage.
parent
39b31707
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
43 deletions
+73
-43
client.js
src/client.js
+1
-1
enrichment.js
src/enrichment.js
+7
-7
enrichment.js
test/enrichment.js
+65
-0
person.js
test/person.js
+0
-35
No files found.
src/client.js
View file @
2fde53da
...
...
@@ -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
);
...
...
src/enrichment.js
View file @
2fde53da
...
...
@@ -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
);
};
test/enrichment.js
0 → 100644
View file @
2fde53da
'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
);
});
});
});
test/person.js
View file @
2fde53da
...
...
@@ -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
);
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment