@@ -341,318 +341,6 @@ describe("Repository Tests", () => {
341341 } ) ;
342342 } ) ;
343343
344- describe ( "Repository Type System" , ( ) => {
345- beforeEach ( ( ) => {
346- cleanupDatabase ( ) ;
347- } ) ;
348-
349- describe ( "Type Definitions" , ( ) => {
350- it ( "has correct enum values and immutability" , ( ) => {
351- expect ( RepositoryType . GLOBUS ) . to . equal ( "globus" ) ;
352- expect ( RepositoryType . METADATA_ONLY ) . to . equal ( "metadata_only" ) ;
353- expect ( Object . keys ( RepositoryType ) . length ) . to . equal ( 2 ) ;
354-
355- expect ( ( ) => {
356- RepositoryType . NEW_TYPE = "new" ;
357- } ) . to . throw ( ) ;
358- expect ( ( ) => {
359- RepositoryType . GLOBUS = "modified" ;
360- } ) . to . throw ( ) ;
361-
362- expect ( ExecutionMethod . TASK ) . to . equal ( "task" ) ;
363- expect ( ExecutionMethod . DIRECT ) . to . equal ( "direct" ) ;
364- } ) ;
365-
366- it ( "Result type handles success and error cases" , ( ) => {
367- const success = Result . ok ( "value" ) ;
368- expect ( success . ok ) . to . be . true ;
369- expect ( success . value ) . to . equal ( "value" ) ;
370- expect ( success . error ) . to . be . undefined ;
371-
372- const error = Result . err ( { code : 404 , message : "Not found" } ) ;
373- expect ( error . ok ) . to . be . false ;
374- expect ( error . error ) . to . deep . equal ( { code : 404 , message : "Not found" } ) ;
375- expect ( error . value ) . to . be . undefined ;
376- } ) ;
377- } ) ;
378-
379- describe ( "Untested Core Functions" , ( ) => {
380- const {
381- createRepositoryData,
382- createGlobusConfig,
383- createRepository,
384- createAllocationResult,
385- } = require ( "../api/repository/types" ) ;
386-
387- const {
388- validateCommonFields,
389- validateRepositoryPath,
390- validateAllocationParams,
391- } = require ( "../api/repository/validation" ) ;
392-
393- const { getRepositoryImplementation } = require ( "../api/repository/factory" ) ;
394-
395- it ( "createRepositoryData creates proper data structures" , ( ) => {
396- const data = createRepositoryData ( {
397- id : "test_repo" ,
398- type : RepositoryType . GLOBUS ,
399- title : "Test Repository" ,
400- desc : "Description" ,
401- capacity : 1000000 ,
402- admins : [ "u/admin1" ] ,
403- typeSpecific : { endpoint : "ep1" } ,
404- } ) ;
405-
406- expect ( data . _key ) . to . equal ( "test_repo" ) ;
407- expect ( data . _id ) . to . equal ( "repo/test_repo" ) ;
408- expect ( data . type ) . to . equal ( "globus" ) ;
409- expect ( data . endpoint ) . to . equal ( "ep1" ) ;
410- } ) ;
411-
412- it ( "createGlobusConfig creates Globus configuration" , ( ) => {
413- const config = createGlobusConfig ( {
414- pub_key : "test-key" ,
415- address : "test.server" ,
416- endpoint : "ep123" ,
417- path : "/data/test" ,
418- domain : "test.org" ,
419- } ) ;
420-
421- expect ( config . pub_key ) . to . equal ( "test-key" ) ;
422- expect ( config . address ) . to . equal ( "test.server" ) ;
423- expect ( config . endpoint ) . to . equal ( "ep123" ) ;
424- expect ( config . path ) . to . equal ( "/data/test" ) ;
425- expect ( config . domain ) . to . equal ( "test.org" ) ;
426- } ) ;
427-
428- it ( "createRepository creates repository objects" , ( ) => {
429- const repo = createRepository ( RepositoryType . GLOBUS , {
430- _id : "repo/test" ,
431- type : RepositoryType . GLOBUS ,
432- title : "Test" ,
433- } ) ;
434-
435- expect ( repo . type ) . to . equal ( RepositoryType . GLOBUS ) ;
436- expect ( repo . data . _id ) . to . equal ( "repo/test" ) ;
437- } ) ;
438-
439- it ( "createAllocationResult creates allocation results" , ( ) => {
440- const taskResult = createAllocationResult ( ExecutionMethod . TASK , { task_id : "123" } ) ;
441- expect ( taskResult . execution_method ) . to . equal ( "task" ) ;
442- expect ( taskResult . task . task_id ) . to . equal ( "123" ) ;
443- expect ( taskResult . result ) . to . be . undefined ;
444-
445- const directResult = createAllocationResult ( ExecutionMethod . DIRECT , null , {
446- status : "completed" ,
447- } ) ;
448- expect ( directResult . execution_method ) . to . equal ( "direct" ) ;
449- expect ( directResult . result . status ) . to . equal ( "completed" ) ;
450- expect ( directResult . task ) . to . be . undefined ;
451- } ) ;
452-
453- it ( "validateCommonFields validates repository common fields" , ( ) => {
454- const validConfig = {
455- id : "test" ,
456- title : "Test Repository" ,
457- capacity : 1000000 ,
458- admins : [ "u/admin" ] ,
459- } ;
460-
461- const result = validateCommonFields ( validConfig ) ;
462- expect ( result . ok ) . to . be . true ;
463-
464- const invalidConfig = {
465- id : "test" ,
466- title : "" ,
467- capacity : - 100 ,
468- admins : [ ] ,
469- } ;
470-
471- const invalidResult = validateCommonFields ( invalidConfig ) ;
472- expect ( invalidResult . ok ) . to . be . false ;
473- } ) ;
474-
475- it ( "validateRepositoryPath validates path ends with ID" , ( ) => {
476- const valid = validateRepositoryPath ( "/data/repos/myrepo" , "myrepo" ) ;
477- expect ( valid . ok ) . to . be . true ;
478-
479- const invalid = validateRepositoryPath ( "/data/repos/other" , "myrepo" ) ;
480- expect ( invalid . ok ) . to . be . false ;
481- expect ( invalid . error . message ) . to . include ( "must end with repository ID" ) ;
482- } ) ;
483-
484- it ( "validateAllocationParams validates allocation parameters" , ( ) => {
485- const validParams = {
486- subject : "d/dataset1" ,
487- size : 1000000 ,
488- } ;
489-
490- const result = validateAllocationParams ( validParams ) ;
491- expect ( result . ok ) . to . be . true ;
492-
493- const invalidParams = {
494- subject : "" ,
495- size : - 1000 ,
496- } ;
497-
498- const invalidResult = validateAllocationParams ( invalidParams ) ;
499- expect ( invalidResult . ok ) . to . be . false ;
500- } ) ;
501-
502- it ( "getRepositoryImplementation returns correct implementations" , ( ) => {
503- const globusImpl = getRepositoryImplementation ( RepositoryType . GLOBUS ) ;
504- const metadataImpl = getRepositoryImplementation ( RepositoryType . METADATA_ONLY ) ;
505- const unknownImpl = getRepositoryImplementation ( "unknown" ) ;
506-
507- expect ( globusImpl ) . to . not . be . null ;
508- expect ( metadataImpl ) . to . not . be . null ;
509- expect ( unknownImpl ) . to . be . null ;
510- } ) ;
511- } ) ;
512-
513- describe ( "Validation" , ( ) => {
514- describe ( "String validation" , ( ) => {
515- runParameterizedTest ( ValidationTestCases . strings , ( testCase ) => {
516- const result = validateNonEmptyString ( testCase . input , "Test field" ) ;
517- expect ( result . ok ) . to . equal ( testCase . expected ) ;
518- if ( ! testCase . expected && testCase . error ) {
519- expect ( result . error . message ) . to . include ( testCase . error ) ;
520- }
521- } ) ;
522- } ) ;
523-
524- describe ( "Path validation" , ( ) => {
525- runParameterizedTest ( ValidationTestCases . paths , ( testCase ) => {
526- const result = validatePOSIXPath ( testCase . input , "Test path" ) ;
527- expect ( result . ok ) . to . equal ( testCase . expected ) ;
528- if ( ! testCase . expected && testCase . error ) {
529- expect ( result . error . message ) . to . include ( testCase . error ) ;
530- }
531- } ) ;
532- } ) ;
533-
534- describe ( "Repository configuration validation" , ( ) => {
535- runParameterizedTest ( RepositoryTestData . globusConfigs , ( testCase ) => {
536- const result = validateGlobusConfig ( testCase . config ) ;
537- expect ( result . ok ) . to . equal ( testCase . valid ) ;
538- if ( ! testCase . valid && testCase . error ) {
539- expect ( result . error . message ) . to . include ( testCase . error ) ;
540- }
541- } ) ;
542-
543- runParameterizedTest ( RepositoryTestData . metadataConfigs , ( testCase ) => {
544- const result = validateMetadataConfig ( testCase . config ) ;
545- expect ( result . ok ) . to . equal ( testCase . valid ) ;
546- if ( ! testCase . valid && testCase . error ) {
547- expect ( result . error . message ) . to . include ( testCase . error ) ;
548- }
549- } ) ;
550- } ) ;
551- } ) ;
552-
553- describe ( "Repository Operations" , ( ) => {
554- let testRepo ;
555-
556- beforeEach ( ( ) => {
557- testRepo = g_db . repo . save ( {
558- _key : "test_repo" ,
559- type : RepositoryType . GLOBUS ,
560- title : "Test Repository" ,
561- capacity : 1000000 ,
562- admins : [ "u/admin1" ] ,
563- endpoint : "ep123" ,
564- path : "/data/test_repo" ,
565- } ) ;
566- } ) ;
567-
568- it ( "creates repositories by type" , ( ) => {
569- const globusResult = createRepositoryByType (
570- RepositoryTestData . globusConfigs [ 0 ] . config ,
571- ) ;
572- expect ( globusResult . ok ) . to . be . true ;
573- expect ( globusResult . value . type ) . to . equal ( RepositoryType . GLOBUS ) ;
574-
575- const metadataResult = createRepositoryByType (
576- RepositoryTestData . metadataConfigs [ 0 ] . config ,
577- ) ;
578- expect ( metadataResult . ok ) . to . be . true ;
579- expect ( metadataResult . value . type ) . to . equal ( RepositoryType . METADATA_ONLY ) ;
580- } ) ;
581-
582- it ( "executes operations on repositories" , ( ) => {
583- const globusRepo = { type : RepositoryType . GLOBUS , data : { _id : "repo/test" } } ;
584- const metadataRepo = {
585- type : RepositoryType . METADATA_ONLY ,
586- data : { _id : "repo/test" } ,
587- } ;
588-
589- const globusOps = executeRepositoryOperation ( globusRepo , "supportsDataOperations" ) ;
590- expect ( globusOps . ok ) . to . be . true ;
591- expect ( globusOps . value ) . to . be . true ;
592-
593- const metadataOps = executeRepositoryOperation (
594- metadataRepo ,
595- "supportsDataOperations" ,
596- ) ;
597- expect ( metadataOps . ok ) . to . be . true ;
598- expect ( metadataOps . value ) . to . be . false ;
599- } ) ;
600-
601- it ( "handles different behavior for repository types" , ( ) => {
602- const globusRepo = RepositoryOps . find ( "test_repo" ) . value ;
603-
604- expect ( RepositoryOps . supportsDataOperations ( globusRepo ) . value ) . to . be . true ;
605-
606- const allocResult = RepositoryOps . createAllocation ( globusRepo , {
607- subject : "d/test" ,
608- size : 1000 ,
609- } ) ;
610-
611- expect ( allocResult . ok ) . to . be . true ;
612- expect ( allocResult . value . execution_method ) . to . equal ( ExecutionMethod . TASK ) ;
613- } ) ;
614- } ) ;
615-
616- describe ( "Implementation Modules" , ( ) => {
617- const globusImpl = require ( "../api/repository/globus" ) ;
618- const metadataImpl = require ( "../api/repository/metadata" ) ;
619-
620- it ( "Globus implementation supports data operations" , ( ) => {
621- const repoData = { _id : "repo/globus1" , capacity : 1000000000 } ;
622-
623- expect ( globusImpl . supportsDataOperations ( repoData ) . value ) . to . be . true ;
624- expect ( globusImpl . getCapacityInfo ( repoData ) . value . supports_quotas ) . to . be . true ;
625-
626- const allocResult = globusImpl . createAllocation ( repoData , {
627- subject : "d/dataset1" ,
628- size : 1000000 ,
629- path : "/data/alloc1" ,
630- } ) ;
631- expect ( allocResult . ok ) . to . be . true ;
632- expect ( allocResult . value . execution_method ) . to . equal ( ExecutionMethod . TASK ) ;
633-
634- const deleteResult = globusImpl . deleteAllocation ( repoData , null ) ;
635- expect ( deleteResult . ok ) . to . be . false ;
636- expect ( deleteResult . error . message ) . to . include ( "Subject ID is required" ) ;
637- } ) ;
638-
639- it ( "Metadata implementation does not support data operations" , ( ) => {
640- const repoData = { _id : "repo/meta1" , capacity : 1000000 } ;
641-
642- expect ( metadataImpl . supportsDataOperations ( repoData ) . value ) . to . be . false ;
643- expect ( metadataImpl . getCapacityInfo ( repoData ) . value . is_metadata_only ) . to . be . true ;
644-
645- const allocResult = metadataImpl . createAllocation ( repoData , {
646- subject : "d/dataset1" ,
647- size : 1000 ,
648- } ) ;
649- expect ( allocResult . ok ) . to . be . true ;
650- expect ( allocResult . value . execution_method ) . to . equal ( ExecutionMethod . DIRECT ) ;
651- expect ( allocResult . value . result . status ) . to . equal ( "completed" ) ;
652- } ) ;
653- } ) ;
654- } ) ;
655-
656344 describe ( "Repository API Routers" , ( ) => {
657345 describe ( "Legacy-Specific Endpoints" , ( ) => {
658346 let setup , apiAdapter ;
0 commit comments