@@ -6,6 +6,8 @@ import esmock from 'esmock'
66import { http , HttpResponse } from 'msw'
77import { setupServer } from 'msw/node'
88
9+ import { CYCLONEDX_JSON_MEDIA_TYPE } from '../src/analysis.js'
10+
911const BACKEND_URL = 'http://localhost:9999'
1012const BACKEND_OPTS = { TRUSTIFY_DA_BACKEND_URL : BACKEND_URL }
1113
@@ -73,13 +75,22 @@ function makeSbom(name, version) {
7375 }
7476}
7577
78+ function mediaTypeWithoutParameters ( contentType ) {
79+ if ( ! contentType ) {
80+ return ''
81+ }
82+ return contentType . split ( ';' ) [ 0 ] . trim ( )
83+ }
84+
7685suite ( 'stackAnalysisBatch' , ( ) => {
7786 let server
7887 let capturedBody
88+ let capturedContentType
7989
8090 suiteSetup ( ( ) => {
8191 server = setupServer (
8292 http . post ( `${ BACKEND_URL } /api/v5/batch-analysis` , async ( { request } ) => {
93+ capturedContentType = request . headers . get ( 'content-type' )
8394 capturedBody = await request . json ( )
8495 const report = { }
8596 for ( const purl of Object . keys ( capturedBody ) ) {
@@ -97,6 +108,7 @@ suite('stackAnalysisBatch', () => {
97108
98109 setup ( ( ) => {
99110 capturedBody = null
111+ capturedContentType = null
100112 } )
101113
102114 test ( 'discovers JS workspace packages, generates SBOMs, and sends batch request' , async ( ) => {
@@ -127,6 +139,7 @@ suite('stackAnalysisBatch', () => {
127139
128140 expect ( result ) . to . be . an ( 'object' )
129141 expect ( capturedBody ) . to . be . an ( 'object' )
142+ expect ( mediaTypeWithoutParameters ( capturedContentType ) ) . to . equal ( CYCLONEDX_JSON_MEDIA_TYPE )
130143 const purls = Object . keys ( capturedBody )
131144 expect ( purls ) . to . include ( 'pkg:npm/app-a@1.0.0' )
132145 expect ( purls ) . to . include ( 'pkg:npm/app-b@2.0.0' )
@@ -164,6 +177,7 @@ suite('stackAnalysisBatch', () => {
164177 expect ( result . metadata . ecosystem ) . to . equal ( 'javascript' )
165178 expect ( result . metadata . successful ) . to . equal ( 2 )
166179 expect ( result . metadata . failed ) . to . equal ( 0 )
180+ expect ( mediaTypeWithoutParameters ( capturedContentType ) ) . to . equal ( CYCLONEDX_JSON_MEDIA_TYPE )
167181 } finally {
168182 cleanup ( )
169183 }
@@ -196,6 +210,7 @@ suite('stackAnalysisBatch', () => {
196210 expect ( result . metadata . failed ) . to . be . at . least ( 1 )
197211 expect ( result . metadata . errors . some ( e => e . phase === 'validation' ) ) . to . be . true
198212 expect ( capturedBody ) . to . be . an ( 'object' )
213+ expect ( mediaTypeWithoutParameters ( capturedContentType ) ) . to . equal ( CYCLONEDX_JSON_MEDIA_TYPE )
199214 expect ( Object . keys ( capturedBody ) ) . to . include ( 'pkg:npm/good@1.0.0' )
200215 } finally {
201216 cleanup ( )
@@ -281,6 +296,7 @@ suite('stackAnalysisBatch', () => {
281296
282297 expect ( result ) . to . be . an ( 'object' )
283298 expect ( capturedBody ) . to . be . an ( 'object' )
299+ expect ( mediaTypeWithoutParameters ( capturedContentType ) ) . to . equal ( CYCLONEDX_JSON_MEDIA_TYPE )
284300 expect ( Object . keys ( capturedBody ) ) . to . include ( 'pkg:npm/web@1.0.0' )
285301 } finally {
286302 cleanup ( )
0 commit comments