@@ -268,4 +268,128 @@ describe('Testing the PUT /cve/:id endpoint in Cve Controller', () => {
268268 } )
269269 } )
270270 } )
271+
272+ context ( 'Positive Tests' , ( ) => {
273+ it ( 'Update CVE record when requestor is secretariat' , ( done ) => {
274+ class OrgRepo {
275+ async getOrgUUID ( ) {
276+ return null
277+ }
278+ }
279+ class CveRepo {
280+ async updateByCveId ( cveId , newCve ) {
281+ expect ( cveId ) . to . equal ( cveIdPublished5 )
282+ expect ( newCve ) . to . have . nested . property ( 'cve.cveMetadata.state' ) . and . to . equal ( 'PUBLISHED' )
283+ return null
284+ }
285+
286+ async findOneByCveId ( ) {
287+ return true
288+ }
289+ }
290+ class CveIdRepo {
291+ async updateByCveId ( cveId , newCve ) {
292+ expect ( cveId ) . to . equal ( cveIdPublished5 )
293+ expect ( newCve ) . to . have . property ( 'state' )
294+ return null
295+ }
296+
297+ async findOneByCveId ( ) {
298+ return true
299+ }
300+ }
301+ class UserRepo {
302+ async getUserUUID ( ) {
303+ return null
304+ }
305+ }
306+ app . route ( '/cve-update-record/:id' )
307+ . put ( ( req , res , next ) => {
308+ const factory = {
309+ getCveIdRepository : ( ) => { return new CveIdRepo ( ) } ,
310+ getCveRepository : ( ) => { return new CveRepo ( ) } ,
311+ getOrgRepository : ( ) => { return new OrgRepo ( ) } ,
312+ getUserRepository : ( ) => { return new UserRepo ( ) }
313+ }
314+ req . ctx . repositories = factory
315+ next ( )
316+ } , cveParams . parsePostParams , cveController . CVE_UPDATE_SINGLE )
317+
318+ chai . request ( app )
319+ . put ( `/cve-update-record/${ cveIdPublished5 } ` )
320+ . set ( cveFixtures . secretariatHeader )
321+ . send ( cvePublishedPass5 )
322+ . end ( ( err , res ) => {
323+ if ( err ) {
324+ done ( err )
325+ }
326+
327+ expect ( res ) . to . have . status ( 200 )
328+ expect ( res ) . to . have . property ( 'body' ) . and . to . be . a ( 'object' )
329+ expect ( res . body ) . to . have . property ( 'updated' ) . and . to . be . a ( 'object' )
330+ expect ( res . body . updated ) . to . have . nested . property ( 'cveMetadata.cveId' ) . and . to . equal ( cveIdPublished5 )
331+ expect ( res . body . updated ) . to . have . nested . property ( 'cveMetadata.state' ) . and . to . equal ( 'PUBLISHED' )
332+ done ( )
333+ } )
334+ } )
335+
336+ it ( 'Update CVE record when requestor is secretariat and valid REJECTED JSON' , ( done ) => {
337+ class OrgRepo {
338+ async getOrgUUID ( ) {
339+ return null
340+ }
341+ }
342+ class CveRepo {
343+ async updateByCveId ( cveId , newCve ) {
344+ return null
345+ }
346+
347+ async findOneByCveId ( ) {
348+ return true
349+ }
350+ }
351+ class CveIdRepo {
352+ async updateByCveId ( cveId , newCve ) {
353+ return null
354+ }
355+
356+ async findOneByCveId ( ) {
357+ return true
358+ }
359+ }
360+ class UserRepo {
361+ async getUserUUID ( ) {
362+ return null
363+ }
364+ }
365+ app . route ( '/cve-update-record-rejected/:id' )
366+ . put ( ( req , res , next ) => {
367+ const factory = {
368+ getCveIdRepository : ( ) => { return new CveIdRepo ( ) } ,
369+ getCveRepository : ( ) => { return new CveRepo ( ) } ,
370+ getOrgRepository : ( ) => { return new OrgRepo ( ) } ,
371+ getUserRepository : ( ) => { return new UserRepo ( ) }
372+ }
373+ req . ctx . repositories = factory
374+ next ( )
375+ } , cveParams . parsePostParams , cveController . CVE_UPDATE_SINGLE )
376+
377+ chai . request ( app )
378+ . put ( `/cve-update-record-rejected/${ cveIdRejected5 } ` )
379+ . set ( cveFixtures . secretariatHeader )
380+ . send ( cveRejectedPass5 )
381+ . end ( ( err , res ) => {
382+ if ( err ) {
383+ done ( err )
384+ }
385+
386+ expect ( res ) . to . have . status ( 200 )
387+ expect ( res ) . to . have . property ( 'body' ) . and . to . be . a ( 'object' )
388+ expect ( res . body ) . to . have . property ( 'updated' ) . and . to . be . a ( 'object' )
389+ expect ( res . body . updated ) . to . have . nested . property ( 'cveMetadata.cveId' ) . and . to . equal ( cveIdRejected5 )
390+ expect ( res . body . updated ) . to . have . nested . property ( 'cveMetadata.state' ) . and . to . equal ( 'REJECTED' )
391+ done ( )
392+ } )
393+ } )
394+ } )
271395} )
0 commit comments