11/* eslint-disable import/first */
22import { forEachObjIndexed } from 'ramda' ;
33import { ConsumerInteraction } from '@pact-foundation/pact-core/src/consumer/index' ;
4- import { isArray } from 'util' ;
54import { TemplateHeaders , V3Request , V3Response } from './types' ;
65import { matcherValueOrString } from './matchers' ;
76import { MatchersV3 } from '../v3' ;
87
8+ type TemplateHeaderArrayValue = string [ ] | MatchersV3 . Matcher < string > [ ] ;
9+
910export const setRequestDetails = (
1011 interaction : ConsumerInteraction ,
1112 req : V3Request
1213) : void => {
1314 interaction . withRequest ( req . method , matcherValueOrString ( req . path ) ) ;
1415 forEachObjIndexed ( ( v , k ) => {
15- interaction . withRequestHeader ( k , 0 , matcherValueOrString ( v ) ) ;
16+ if ( Array . isArray ( v ) ) {
17+ ( v as TemplateHeaderArrayValue ) . forEach ( ( header , index ) => {
18+ interaction . withRequestHeader ( k , index , matcherValueOrString ( header ) ) ;
19+ } ) ;
20+ } else {
21+ interaction . withRequestHeader ( k , 0 , matcherValueOrString ( v ) ) ;
22+ }
1623 } , req . headers ) ;
1724
1825 forEachObjIndexed ( ( v , k ) => {
19- if ( isArray ( v ) ) {
26+ if ( Array . isArray ( v ) ) {
2027 ( v as unknown [ ] ) . forEach ( ( vv , i ) => {
2128 interaction . withQuery ( k , i , matcherValueOrString ( vv ) ) ;
2229 } ) ;
@@ -37,6 +44,7 @@ export const setResponseDetails = (
3744 } , res . headers ) ;
3845} ;
3946
47+ // TODO: this might need to consider an array of values
4048export const contentTypeFromHeaders = (
4149 headers : TemplateHeaders | undefined ,
4250 defaultContentType : string
0 commit comments