@@ -156,7 +156,7 @@ describe('Phase Products', () => {
156156 request ( server )
157157 . delete ( `/v4/projects/999/phases/${ phaseId } /products/${ productId } ` )
158158 . set ( {
159- Authorization : `Bearer ${ testUtil . jwts . manager } ` ,
159+ Authorization : `Bearer ${ testUtil . jwts . connectAdmin } ` ,
160160 } )
161161 . expect ( 'Content-Type' , / j s o n / )
162162 . expect ( 404 , done ) ;
@@ -166,7 +166,7 @@ describe('Phase Products', () => {
166166 request ( server )
167167 . delete ( `/v4/projects/${ projectId } /phases/99999/products/${ productId } ` )
168168 . set ( {
169- Authorization : `Bearer ${ testUtil . jwts . manager } ` ,
169+ Authorization : `Bearer ${ testUtil . jwts . connectAdmin } ` ,
170170 } )
171171 . expect ( 'Content-Type' , / j s o n / )
172172 . expect ( 404 , done ) ;
@@ -176,7 +176,7 @@ describe('Phase Products', () => {
176176 request ( server )
177177 . delete ( `/v4/projects/${ projectId } /phases/${ phaseId } /products/99999` )
178178 . set ( {
179- Authorization : `Bearer ${ testUtil . jwts . manager } ` ,
179+ Authorization : `Bearer ${ testUtil . jwts . connectAdmin } ` ,
180180 } )
181181 . expect ( 'Content-Type' , / j s o n / )
182182 . expect ( 404 , done ) ;
@@ -192,6 +192,60 @@ describe('Phase Products', () => {
192192 . end ( err => expectAfterDelete ( projectId , phaseId , productId , err , done ) ) ;
193193 } ) ;
194194
195+ it ( 'should return 204 if requested by admin' , ( done ) => {
196+ request ( server )
197+ . delete ( `/v4/projects/${ projectId } /phases/${ phaseId } /products/${ productId } ` )
198+ . set ( {
199+ Authorization : `Bearer ${ testUtil . jwts . connectAdmin } ` ,
200+ } )
201+ . expect ( 204 )
202+ . end ( done ) ;
203+ } ) ;
204+
205+ it ( 'should return 204 if requested by manager which is a member' , ( done ) => {
206+ models . ProjectMember . create ( {
207+ id : 3 ,
208+ userId : testUtil . userIds . manager ,
209+ projectId,
210+ role : 'manager' ,
211+ isPrimary : false ,
212+ createdBy : 1 ,
213+ updatedBy : 1 ,
214+ } ) . then ( ( ) => {
215+ request ( server )
216+ . delete ( `/v4/projects/${ projectId } /phases/${ phaseId } /products/${ productId } ` )
217+ . set ( {
218+ Authorization : `Bearer ${ testUtil . jwts . manager } ` ,
219+ } )
220+ . expect ( 204 )
221+ . end ( done ) ;
222+ } ) ;
223+ } ) ;
224+
225+ it ( 'should return 403 if requested by manager which is not a member' , ( done ) => {
226+ request ( server )
227+ . delete ( `/v4/projects/${ projectId } /phases/${ phaseId } /products/${ productId } ` )
228+ . set ( {
229+ Authorization : `Bearer ${ testUtil . jwts . manager } ` ,
230+ } )
231+ . expect ( 403 )
232+ . end ( done ) ;
233+ } ) ;
234+
235+ it ( 'should return 403 if requested by non-member copilot' , ( done ) => {
236+ models . ProjectMember . destroy ( {
237+ where : { userId : testUtil . userIds . copilot , projectId } ,
238+ } ) . then ( ( ) => {
239+ request ( server )
240+ . delete ( `/v4/projects/${ projectId } /phases/${ phaseId } /products/${ productId } ` )
241+ . set ( {
242+ Authorization : `Bearer ${ testUtil . jwts . copilot } ` ,
243+ } )
244+ . expect ( 403 )
245+ . end ( done ) ;
246+ } ) ;
247+ } ) ;
248+
195249 describe ( 'Bus api' , ( ) => {
196250 let createEventSpy ;
197251 const sandbox = sinon . sandbox . create ( ) ;
0 commit comments