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
6634f9e7
Commit
6634f9e7
authored
Jan 19, 2015
by
Alex MacCaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix tests (and a few bugs)
parent
0716f356
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
75 additions
and
14 deletions
+75
-14
client.js
src/client.js
+1
-2
resource.js
src/resource.js
+18
-4
watchlist.js
src/watchlist.js
+0
-1
client.js
test/client.js
+7
-7
watchlist.json
test/fixtures/watchlist.json
+12
-0
watchlist.js
test/watchlist.js
+37
-0
No files found.
src/client.js
View file @
6634f9e7
...
...
@@ -51,8 +51,7 @@ ClearbitClient.prototype.url = function (options) {
ClearbitClient
.
prototype
.
request
=
function
(
options
)
{
options
=
_
.
defaults
(
options
,
{
method
:
'get'
,
query
:
{}
method
:
'get'
});
return
needle
.
requestAsync
(
...
...
src/resource.js
View file @
6634f9e7
...
...
@@ -17,15 +17,20 @@ function ClearbitResource (data) {
_
.
extend
(
this
,
data
);
}
ClearbitResource
.
extractParams
=
function
(
params
)
{
return
_
.
omit
(
params
||
{},
'path'
,
'method'
,
'params'
,
'client'
,
'api'
,
'stream'
);
ClearbitResource
.
extractParams
=
function
(
options
)
{
var
params
=
_
.
omit
(
options
||
{},
'path'
,
'method'
,
'params'
,
'client'
,
'api'
,
'stream'
);
return
_
.
isEmpty
(
params
)
?
null
:
params
;
};
ClearbitResource
.
get
=
Promise
.
method
(
function
(
path
,
options
)
{
options
=
_
.
extend
({
path
:
path
,
method
:
'get'
,
params
:
this
.
extractParams
(
options
)
query
:
this
.
extractParams
(
options
)
},
this
.
options
,
options
||
{});
return
this
.
client
.
request
(
options
)
...
...
@@ -50,6 +55,9 @@ ClearbitResource.post = Promise.method(function (path, options) {
return
this
.
client
.
request
(
options
)
.
bind
(
this
)
.
then
(
function
(
data
)
{
return
new
this
(
data
);
})
.
catch
(
isUnknownRecord
,
function
()
{
throw
new
this
.
NotFoundError
(
this
.
name
+
' not found'
);
});
...
...
@@ -63,7 +71,13 @@ function createErrors (name) {
}
exports
.
create
=
function
(
name
,
options
)
{
var
Resource
=
function
()
{
var
Resource
=
function
(
data
)
{
if
(
_
.
isArray
(
data
))
{
return
data
.
map
(
function
(
item
){
return
new
this
.
constructor
(
item
);
}.
bind
(
this
));
}
ClearbitResource
.
apply
(
this
,
arguments
);
};
...
...
src/watchlist.js
View file @
6634f9e7
'use strict'
;
var
assert
=
require
(
'assert'
);
var
resource
=
require
(
'./resource'
);
var
_
=
require
(
'lodash'
);
...
...
test/client.js
View file @
6634f9e7
...
...
@@ -34,22 +34,22 @@ describe('Client', function () {
});
describe
(
'#
base
'
,
function
()
{
describe
(
'#
endpoint
'
,
function
()
{
it
(
'requires an API'
,
function
()
{
expect
(
client
.
base
.
bind
(
client
,
{}))
expect
(
client
.
endpoint
.
bind
(
client
,
{}))
.
to
.
throw
(
/API must be specified/
);
});
it
(
'can generate the default
base
'
,
function
()
{
expect
(
client
.
base
({
it
(
'can generate the default
endpoint
'
,
function
()
{
expect
(
client
.
endpoint
({
api
:
'person'
}))
.
to
.
equal
(
'https://person.clearbit.com/v1'
);
});
it
(
'can generate a streaming
base
'
,
function
()
{
expect
(
client
.
base
({
it
(
'can generate a streaming
endpoint
'
,
function
()
{
expect
(
client
.
endpoint
({
api
:
'person'
,
stream
:
true
}))
...
...
@@ -57,7 +57,7 @@ describe('Client', function () {
});
it
(
'can set a custom version'
,
function
()
{
expect
(
client
.
base
({
expect
(
client
.
endpoint
({
api
:
'person'
,
version
:
'2'
}))
...
...
test/fixtures/watchlist.json
0 → 100644
View file @
6634f9e7
[
{
"id"
:
"6ffa17f3-2653-485f-9129-73bdaa88087a"
,
"name"
:
{
"fullName"
:
"Joe Schmo"
},
"addresses"
:
[],
"list"
:
"ofac_sdn"
,
"remarks"
:
null
,
"type"
:
"entity"
}
]
test/watchlist.js
0 → 100644
View file @
6634f9e7
'use strict'
;
var
expect
=
require
(
'chai'
).
expect
;
var
nock
=
require
(
'nock'
);
var
Watchlist
=
require
(
'../'
)(
'k'
).
Watchlist
;
describe
(
'Watchlist'
,
function
()
{
var
mock
;
before
(
function
()
{
mock
=
nock
(
'https://watchlist.clearbit.com'
);
});
after
(
nock
.
cleanAll
);
afterEach
(
function
()
{
mock
.
done
();
});
describe
(
'Watchlist#search'
,
function
()
{
var
watchlist
=
require
(
'./fixtures/watchlist'
);
it
(
'can search a watchlist by name'
,
function
()
{
mock
.
post
(
'/v1/search/all'
)
.
reply
(
200
,
watchlist
);
return
Watchlist
.
search
({
name
:
'Joe'
})
.
then
(
function
(
watchlist
)
{
// console.log(watchlist.constructor)
expect
(
watchlist
[
0
])
.
to
.
be
.
an
.
instanceOf
(
Watchlist
)
.
and
.
have
.
property
(
'id'
,
watchlist
.
id
);
});
});
});
});
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