@@ -8,18 +8,49 @@ import app from '..'
88const { expect } = chai
99const entity = {
1010 name : randomWords ( ) ,
11- type : 'Test'
11+ type : 'Test' ,
12+ contacts : [ ]
13+ }
14+ const contact = {
15+ name : randomWords ( ) ,
16+ phone : [
17+ {
18+ number : ( Math . floor ( Math . random ( ) * Math . floor ( 100000000000 ) ) ) . toString ( )
19+ }
20+ ] ,
21+ email : [
22+ {
23+ address : `${ randomWords ( ) } @test.test`
24+ }
25+ ]
1226}
1327
14- describe ( 'Entity positive tests' , ( ) => {
28+ describe ( 'Entity tests' , ( ) => {
1529 const authed = new Login ( )
1630 let token
1731
1832 before ( async ( ) => {
1933 await authed . setToken ( )
2034 token = await authed . getToken ( )
35+
36+ const contactResponse = await request ( app )
37+ . post ( '/contact' )
38+ . set ( 'Accept' , 'application/json' )
39+ . set ( 'token' , token )
40+ . send ( contact )
41+ . expect ( 'Content-Type' , 'text/html; charset=utf-8' )
42+ . expect ( 201 )
43+
44+ contact . id = contactResponse . text . replace ( ' created' , '' )
45+ entity . contacts . push ( { id : contact . id , title : 'test' } )
2146 } )
2247 after ( async ( ) => {
48+ await request ( app )
49+ . delete ( `/contact/${ contact . id } ` )
50+ . set ( 'Accept' , 'application/json' )
51+ . set ( 'token' , token )
52+ . expect ( 'Content-Type' , 'text/html; charset=utf-8' )
53+ . expect ( 200 )
2354 await authed . destroyToken ( )
2455 } )
2556
@@ -88,6 +119,7 @@ describe('Entity positive tests', () => {
88119 } )
89120 it ( 'should update an entity' , done => {
90121 entity . name = randomWords ( )
122+ entity . checkIn = { test : 'test' }
91123 request ( app )
92124 . put ( `/entity` )
93125 . set ( 'Accept' , 'application/json' )
@@ -101,6 +133,69 @@ describe('Entity positive tests', () => {
101133 done ( )
102134 } )
103135 } )
136+ it ( 'should add an contact to an entity' , done => {
137+ const contactIds = { contacts : [ { id : contact . id , title : 'test' } ] }
138+ request ( app )
139+ . post ( `/entity/link/${ entity . id } ` )
140+ . set ( 'Accept' , 'application/json' )
141+ . set ( 'token' , token )
142+ . send ( contactIds )
143+ . expect ( 'Content-Type' , 'text/html; charset=utf-8' )
144+ . expect ( 200 )
145+ . end ( ( err , res ) => {
146+ if ( err ) return done ( err )
147+ expect ( res . text ) . to . equal ( `Linking successful/already exists for entity with ID ${ entity . id } ` )
148+ done ( )
149+ } )
150+ } )
151+ it ( 'should not add an contact to an entity' , done => {
152+ const contactIds = { contacts : [ { id : uuid ( ) } ] }
153+ request ( app )
154+ . post ( `/entity/link/abc123` )
155+ . set ( 'Accept' , 'application/json' )
156+ . set ( 'token' , token )
157+ . send ( contactIds )
158+ . expect ( 'Content-Type' , 'text/html; charset=utf-8' )
159+ . expect ( 400 )
160+ . end ( ( err , res ) => {
161+ if ( err ) return done ( err )
162+ expect ( res . text ) . to . equal ( `Bad Request` )
163+ done ( )
164+ } )
165+ } )
166+
167+
168+
169+ it ( 'should remove a contact from an entity' , done => {
170+ const contactIds = { contacts : [ { id : contact . id , title : 'test' } ] }
171+ request ( app )
172+ . post ( `/entity/unlink/${ entity . id } ` )
173+ . set ( 'Accept' , 'application/json' )
174+ . set ( 'token' , token )
175+ . send ( contactIds )
176+ . expect ( 'Content-Type' , 'text/html; charset=utf-8' )
177+ . expect ( 200 )
178+ . end ( ( err , res ) => {
179+ if ( err ) return done ( err )
180+ expect ( res . text ) . to . equal ( `Unlinking successful for entity with ID ${ entity . id } ` )
181+ done ( )
182+ } )
183+ } )
184+ it ( 'should not remove a contact from an entity' , done => {
185+ const contactIds = { contacts : [ { id : uuid ( ) } ] }
186+ request ( app )
187+ . post ( `/entity/unlink/abc123` )
188+ . set ( 'Accept' , 'application/json' )
189+ . set ( 'token' , token )
190+ . send ( contactIds )
191+ . expect ( 'Content-Type' , 'text/html; charset=utf-8' )
192+ . expect ( 400 )
193+ . end ( ( err , res ) => {
194+ if ( err ) return done ( err )
195+ expect ( res . text ) . to . equal ( `Bad Request` )
196+ done ( )
197+ } )
198+ } )
104199 it ( 'Positive Test for CSV Dump on Entity' , ( done ) => {
105200 request ( app )
106201 . get ( '/csv/Entity' )
0 commit comments