1- import { LocalRegistry } from './helpers'
2- import { MESSAGE_SEVERITY , VALIDATION_RULES_SEVERITY_LEVEL_ERROR } from '../src'
1+ import { errorNotificationMatcher , LocalRegistry , notificationsMatcher } from './helpers'
2+ import { VALIDATION_RULES_SEVERITY_LEVEL_ERROR } from '../src'
33
44describe ( 'Reference bundling test' , ( ) => {
55 test ( 'external references should be bundled' , async ( ) => {
@@ -9,19 +9,22 @@ describe('Reference bundling test', () => {
99 expect ( result . documents . get ( 'openapi.yaml' ) ?. dependencies ) . toEqual ( [ 'reference.yaml' ] )
1010 } )
1111
12- test ( 'should throw on missing external reference' , async ( ) => {
12+ test ( 'should throw on missing external reference if error severity level configured ' , async ( ) => {
1313 const pkg = LocalRegistry . openPackage ( 'reference-bundling/case2' )
1414
1515 await expect (
1616 pkg . publish ( pkg . packageId , { validationRulesSeverity : { brokenRefs : VALIDATION_RULES_SEVERITY_LEVEL_ERROR } } ) ,
1717 ) . rejects . toThrow ( / d o e s n o t e x i s t / )
1818 } )
1919
20- test ( 'should not throw on missing external reference' , async ( ) => {
20+ test ( 'should collect missing external reference notifications if severity level is not configured ' , async ( ) => {
2121 const pkg = LocalRegistry . openPackage ( 'reference-bundling/case2' )
2222 const result = await pkg . publish ( pkg . packageId )
2323
24- expect ( result . notifications . filter ( ( { severity } ) => severity === MESSAGE_SEVERITY . Error ) . length ) . toEqual ( 2 )
24+ expect ( result ) . toEqual ( notificationsMatcher ( [
25+ errorNotificationMatcher ( 'references an invalid location' ) ,
26+ errorNotificationMatcher ( 'does not exist' ) ,
27+ ] ) )
2528 expect ( result . operations . size ) . toBe ( 1 )
2629 expect ( result . documents . get ( 'openapi.yaml' ) ?. dependencies . length ) . toBe ( 0 )
2730 } )
@@ -36,40 +39,43 @@ describe('Reference bundling test', () => {
3639 ] )
3740 } )
3841
39- test ( 'should throw on missing transitive external reference' , async ( ) => {
42+ test ( 'should throw on missing transitive external reference if error severity level configured ' , async ( ) => {
4043 const pkg = LocalRegistry . openPackage ( 'reference-bundling/case4' )
4144
4245 await expect (
4346 pkg . publish ( pkg . packageId , { validationRulesSeverity : { brokenRefs : VALIDATION_RULES_SEVERITY_LEVEL_ERROR } } ) ,
4447 ) . rejects . toThrow ( / d o e s n o t e x i s t / )
4548 } )
4649
47- test ( 'should not throw on missing transitive external reference' , async ( ) => {
50+ test ( 'should collect notifications when transitive external reference is missing if severity level is not configured ' , async ( ) => {
4851 const pkg = LocalRegistry . openPackage ( 'reference-bundling/case4' )
4952 const result = await pkg . publish ( pkg . packageId )
5053
51- expect ( result . notifications . filter ( ( { severity } ) => severity === MESSAGE_SEVERITY . Error ) . length ) . toEqual ( 2 )
54+ expect ( result ) . toEqual ( notificationsMatcher ( [
55+ errorNotificationMatcher ( 'references an invalid location' ) ,
56+ errorNotificationMatcher ( 'does not exist' ) ,
57+ ] ) )
5258 expect ( result . operations . size ) . toBe ( 1 )
5359 expect ( result . documents . get ( 'openapi.yaml' ) ?. dependencies ) . toEqual ( [ 'reference.yaml' ] )
5460 } )
5561
56- test ( 'should throw on missing internal reference' , async ( ) => {
62+ test ( 'should throw on missing internal reference if error severity level configured ' , async ( ) => {
5763 const pkg = LocalRegistry . openPackage ( 'reference-bundling/case5' )
5864
5965 await expect (
6066 pkg . publish ( pkg . packageId , { validationRulesSeverity : { brokenRefs : VALIDATION_RULES_SEVERITY_LEVEL_ERROR } } ) ,
6167 ) . rejects . toThrow ( / r e f e r e n c e s a n i n v a l i d l o c a t i o n / )
6268 } )
6369
64- test ( 'should not throw on missing internal reference' , async ( ) => {
70+ test ( 'should collect missing internal reference notification if severity level is not configured ' , async ( ) => {
6571 const pkg = LocalRegistry . openPackage ( 'reference-bundling/case5' )
6672 const result = await pkg . publish ( pkg . packageId )
6773
68- expect ( result . notifications . filter ( ( { severity } ) => severity === MESSAGE_SEVERITY . Error ) . length ) . toEqual ( 1 )
74+ expect ( result ) . toEqual ( notificationsMatcher ( [ errorNotificationMatcher ( 'references an invalid location' ) ] ) )
6975 expect ( result . operations . size ) . toBe ( 1 )
7076 } )
7177
72- test ( 'should throw on non-textual external reference' , async ( ) => {
78+ test ( 'should throw on non-textual external reference if error severity level configured ' , async ( ) => {
7379 const pkg = LocalRegistry . openPackage ( 'reference-bundling/case6' )
7480 await expect (
7581 pkg . publish ( pkg . packageId , { validationRulesSeverity : { brokenRefs : VALIDATION_RULES_SEVERITY_LEVEL_ERROR } } ) ,
0 commit comments