11import axios from 'axios' ;
22import AxiosMockAdapter from 'axios-mock-adapter' ;
33import { CalmHubDocumentLoader } from './calmhub-document-loader' ;
4+ import { SchemaDirectory } from '../schema-directory' ;
45
56const calmHubBaseUrl = 'http://local-calmhub' ;
67
78const ax = axios . create ( { baseURL : calmHubBaseUrl } ) ;
89const mock = new AxiosMockAdapter ( ax ) ;
910
10- mock . onGet ( '/calm/ schemas/2025-03/meta/core.json' ) . reply ( 200 , {
11+ mock . onGet ( '/schemas/2025-03/meta/core.json' ) . reply ( 200 , {
1112 '$id' : 'https://calm.finos.org/calm/schemas/2025-03/meta/core.json' ,
1213 'value' : 'test'
1314} ) ;
1415
1516describe ( 'calmhub-document-loader' , ( ) => {
16- let calmHubDocumentLoader ;
17+ let calmHubDocumentLoader : CalmHubDocumentLoader ;
18+ let schemaDirectory : SchemaDirectory ;
1719 beforeEach ( ( ) => {
1820 calmHubDocumentLoader = new CalmHubDocumentLoader ( calmHubBaseUrl , false , ax ) ;
21+ calmHubDocumentLoader . initialise ( schemaDirectory ) ;
1922 } ) ;
2023
2124 it ( 'loads a document from CalmHub' , async ( ) => {
22- const calmHubUrl = 'https:// calm.finos.org/calm /schemas/2025-03/meta/core.json' ;
25+ const calmHubUrl = 'calm: /schemas/2025-03/meta/core.json' ;
2326 const document = await calmHubDocumentLoader . loadMissingDocument ( calmHubUrl , 'schema' ) ;
2427 expect ( document ) . toEqual ( {
2528 '$id' : 'https://calm.finos.org/calm/schemas/2025-03/meta/core.json' ,
@@ -28,7 +31,13 @@ describe('calmhub-document-loader', () => {
2831 } ) ;
2932
3033 it ( 'throws an error when the document is not found' , async ( ) => {
31- const calmHubUrl = 'https://calm.finos.org/calm/schemas/2025-03/meta/nonexistent.json' ;
34+ const calmHubUrl = 'calm:/schemas/2025-03/meta/nonexistent.json' ;
35+
36+ await expect ( calmHubDocumentLoader . loadMissingDocument ( calmHubUrl , 'schema' ) ) . rejects . toThrow ( ) ;
37+ } ) ;
38+
39+ it ( 'throws an error when the protocol is not calm:' , async ( ) => {
40+ const calmHubUrl = 'https://not.calmhub.com/schemas/2025-03/meta/nonexistent.json' ;
3241
3342 await expect ( calmHubDocumentLoader . loadMissingDocument ( calmHubUrl , 'schema' ) ) . rejects . toThrow ( ) ;
3443 } ) ;
0 commit comments