11var Pipedrive = require ( './../..' ) ;
22var assert = require ( 'chai' ) . assert ;
3+ var _ = require ( 'lodash' ) ;
34
45var API_TOKEN = process . env . API_TOKEN ;
56if ( ! API_TOKEN ) {
@@ -16,7 +17,35 @@ describe('client', function () {
1617 strictClient = new Pipedrive . Client ( API_TOKEN , { strictMode : true } ) ;
1718 } ) ;
1819
19- describe ( '.getAll()' , function ( ) {
20+
21+ describe ( 'client.on()' , function ( ) {
22+ it ( 'should allow event binding to connect and deal adding' , function ( done ) {
23+ this . timeout ( 10000 ) ;
24+
25+ var deal = { title : 'Client-nodejs - .on() test' , value : 10000 , currency : 'EUR' } ;
26+
27+ strictClient . on ( 'connect' , function ( ) {
28+ strictClient . Deals . add ( deal , function ( error , result ) {
29+ deal . id = result . id ;
30+ } ) ;
31+ } ) ;
32+
33+ strictClient . on ( 'deal.added' , function ( event , data ) {
34+ assert . equal ( data . current . title , deal . title ) ;
35+ assert . equal ( data . current . value , deal . value ) ;
36+ assert . equal ( data . current . currency , deal . currency ) ;
37+
38+ strictClient . removeAllListeners ( ) ;
39+
40+ //cleanup
41+ strictClient . Deals . remove ( deal . id , function ( ) {
42+ done ( ) ;
43+ } ) ;
44+ } ) ;
45+ } ) ;
46+ } ) ;
47+
48+ describe ( 'collection.getAll()' , function ( ) {
2049 it ( 'should list filters and deals' , function ( done ) {
2150 client . Filters . getAll ( { type : 'deals' } , function ( filtersListErr , filtersList ) {
2251
@@ -37,7 +66,7 @@ describe('client', function () {
3766 } ) ;
3867 } ) ;
3968
40- describe ( '.add() & .getItem()' , function ( ) {
69+ describe ( 'collection .add() & collection .getItem()' , function ( ) {
4170 it ( 'should create and get deal' , function ( done ) {
4271
4372 var payloadDeal = {
@@ -66,34 +95,7 @@ describe('client', function () {
6695 } ) ;
6796 } ) ;
6897
69- describe ( '.on()' , function ( ) {
70- it ( 'should allow event binding to connect and deal adding' , function ( done ) {
71- this . timeout ( 10000 ) ;
72-
73- var deal = { title : 'Client-nodejs - .on() test' , value : 10000 , currency : 'EUR' } ;
74-
75- strictClient . on ( 'connect' , function ( ) {
76- strictClient . Deals . add ( deal , function ( error , result ) {
77- deal . id = result . id ;
78- } ) ;
79- } ) ;
80-
81- strictClient . on ( 'deal.added' , function ( event , data ) {
82- assert . equal ( data . current . title , deal . title ) ;
83- assert . equal ( data . current . value , deal . value ) ;
84- assert . equal ( data . current . currency , deal . currency ) ;
85-
86- strictClient . removeAllListeners ( ) ;
87-
88- //cleanup
89- strictClient . Deals . remove ( deal . id , function ( ) {
90- done ( ) ;
91- } ) ;
92- } ) ;
93- } ) ;
94- } ) ;
95-
96- describe ( '.find()' , function ( ) {
98+ describe ( 'сollection.find()' , function ( ) {
9799 it ( 'should find first person by name' , function ( done ) {
98100 client . Persons . getAll ( function ( err , listedPersons ) {
99101 assert . isTrue ( listedPersons . length > 0 ) ;
@@ -108,5 +110,21 @@ describe('client', function () {
108110 } ) ;
109111 } ) ;
110112 } )
113+ } ) ;
114+
115+ describe ( 'item.getUpdates()' , function ( ) {
116+ it ( 'should get changes deal had' , function ( done ) {
117+ client . Deals . getAll ( { start : 0 , limit : 1 } , function ( dealsListErr , dealsList ) {
118+ if ( dealsListErr ) console . log ( dealsListErr ) ;
119+ var deal = _ . first ( dealsList ) ;
120+
121+ deal . getUpdates ( function ( err , updates ) {
122+ assert . isTrue ( updates . length > 0 ) ;
123+ assert . equal ( updates [ 0 ] . object , 'dealChange' ) ;
124+
125+ done ( ) ;
126+ } ) ;
127+ } ) ;
128+ } ) ;
111129 } )
112130} ) ;
0 commit comments