@@ -14,6 +14,7 @@ import {
1414 PluginIdSchema ,
1515 URISchema ,
1616 PathnameSchema ,
17+ RouteBasePathSchema ,
1718 ContentVisibilitySchema ,
1819} from '../validationSchemas' ;
1920
@@ -24,8 +25,9 @@ function createTestHelpers({
2425 schema : Joi . Schema ;
2526 defaultValue ?: unknown ;
2627} ) {
27- function testOK ( value : unknown ) {
28- expect ( Joi . attempt ( value , schema ) ) . toEqual ( value ?? defaultValue ) ;
28+ function testOK ( value : unknown , options ?: { normalizedValue ?: unknown } ) {
29+ const expectedValue = options ?. normalizedValue ?? value ?? defaultValue ;
30+ expect ( Joi . attempt ( value , schema ) ) . toEqual ( expectedValue ) ;
2931 }
3032
3133 function testFail ( value : unknown ) {
@@ -168,6 +170,29 @@ describe('validation schemas', () => {
168170 testFail ( 'https://github.com/foo' ) ;
169171 } ) ;
170172
173+ it ( 'routeBasePathSchema' , ( ) => {
174+ const { testFail, testOK} = createTestHelpers ( {
175+ schema : RouteBasePathSchema ,
176+ defaultValue : undefined ,
177+ } ) ;
178+
179+ testOK ( '' , { normalizedValue : '/' } ) ;
180+ testOK ( '/' ) ;
181+ testOK ( '/foo' , { normalizedValue : '/foo' } ) ;
182+ testOK ( 'foo' , { normalizedValue : '/foo' } ) ;
183+ testOK ( 'blog' , { normalizedValue : '/blog' } ) ;
184+ testOK ( 'blog/' , { normalizedValue : '/blog/' } ) ;
185+ testOK ( 'prefix/blog' , { normalizedValue : '/prefix/blog' } ) ;
186+ testOK ( 'prefix/blog/' , { normalizedValue : '/prefix/blog/' } ) ;
187+ testOK ( '/prefix/blog' , { normalizedValue : '/prefix/blog' } ) ;
188+ testOK ( undefined ) ;
189+
190+ testFail ( 3 ) ;
191+ testFail ( [ ] ) ;
192+ testFail ( null ) ;
193+ testFail ( { } ) ;
194+ } ) ;
195+
171196 it ( 'contentVisibilitySchema' , ( ) => {
172197 const { testFail, testOK} = createTestHelpers ( {
173198 schema : ContentVisibilitySchema ,
0 commit comments