Skip to content

Commit e8c60e4

Browse files
committed
IND-524 added functional tests, moved unit tests
1 parent c16735e commit e8c60e4

File tree

5 files changed

+57
-7
lines changed

5 files changed

+57
-7
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,13 @@ To read more about ad hoc data change event listeners, check out [examples/live-
248248

249249
The Pipedrive REST API documentation can be found at https://developers.pipedrive.com/v1
250250

251+
#Testing
252+
To run unit tests, execute `npm run tests`
253+
254+
To run integration tests, you need to provide API token with environment variables:
255+
256+
```export PIPEDRIVE_API_TOKEN='xxxxxx' && npm run test:functional```
257+
251258
# Licence
252259

253260
This Pipedrive API client is distributed under the MIT licence.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"url": "http://github.com/pipedrive/client-nodejs.git"
2323
},
2424
"scripts": {
25-
"test": "./node_modules/mocha/bin/mocha ./test"
25+
"test": "./node_modules/mocha/bin/mocha ./test/unit",
26+
"test:functional": "./node_modules/mocha/bin/mocha ./test/functional"
2627
},
2728
"dependencies": {
2829
"async": "~0.9.0",

test/functional/client.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
var should = require('should');
2+
var apiToken = process.env.PIPEDRIVE_API_TOKEN || '';
3+
4+
//fixture — need deal with id 1
5+
describe('client integration tests', function() {
6+
7+
it('getting non-existant deal should return error', function(done) {
8+
var Pipedrive = require('./../..'),
9+
pipedrive = new Pipedrive.Client(apiToken, { strictMode: true });
10+
11+
pipedrive.Deals.get(99999, function(err, deal) {
12+
should.notEqual(err, null);
13+
should.equal(err.message, 'Pipedrive API error:Deal not found');
14+
15+
done();
16+
});
17+
18+
should(pipedrive.on).be.a.Function();
19+
});
20+
21+
it('adding non-existant product to existing deal (with id 1) should return error string in callback', function(done) {
22+
var Pipedrive = require('./../..'),
23+
pipedrive = new Pipedrive.Client(apiToken, { strictMode: true });
24+
25+
pipedrive.Deals.get(1, function(err, deal) {
26+
should.equal(err, null);
27+
28+
deal.addProduct({
29+
product_id: 999999,
30+
quantity: 1,
31+
item_price: 0
32+
}, function (addErr, addData) {
33+
34+
should.notEqual(addErr, null);
35+
should.equal(addErr.message, 'Pipedrive API error:Product(s) 1 not found.');
36+
done();
37+
});
38+
});
39+
40+
should(pipedrive.on).be.a.Function();
41+
});
42+
43+
});

test/client.js renamed to test/unit/client.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ var should = require('should');
33
describe('client module', function() {
44

55
it('should expose some of the main object types', function() {
6-
var Pipedrive = require('./..'),
6+
var Pipedrive = require('./../..'),
77
pipedrive = new Pipedrive.Client('apitoken'),
8-
blueprint = require('./../lib/blueprint');
8+
blueprint = require('./../../lib/blueprint');
99

1010
// iterate through all top level objects which should be exposed, e.g. pipedrive.Deals, ...
1111
blueprint.apiObjects.forEach(function(obj) {
@@ -14,10 +14,9 @@ describe('client module', function() {
1414
});
1515

1616
it('should expose .on() listener in strict mode', function() {
17-
var Pipedrive = require('./..'),
17+
var Pipedrive = require('./../..'),
1818
pipedrive = new Pipedrive.Client('apitoken', { strictMode: true });
1919

2020
should(pipedrive.on).be.a.Function();
2121
});
22-
2322
});

test/index.js renamed to test/unit/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ var should = require('should');
33
describe('main module', function() {
44

55
it('should be requireable without errors', function() {
6-
var Pipedrive = require('./..');
6+
var Pipedrive = require('./../..');
77
});
88

99
it('should expose top-level functionality', function() {
10-
var Pipedrive = require('./..');
10+
var Pipedrive = require('./../..');
1111

1212
should(Pipedrive.Client).be.a.Function();
1313
should(Pipedrive.authenticate).be.a.Function();

0 commit comments

Comments
 (0)