@@ -393,4 +393,68 @@ describe('SiteCollection', () => {
393393 } ) ;
394394 } ) ;
395395 } ) ;
396+
397+ describe ( 'allByEnrollmentProductCode' , ( ) => {
398+ let mockSiteEnrollmentCollection ;
399+
400+ beforeEach ( ( ) => {
401+ mockSiteEnrollmentCollection = {
402+ allSiteIdsByProductCode : stub ( ) ,
403+ } ;
404+ mockEntityRegistry . getCollection = stub ( )
405+ . withArgs ( 'SiteEnrollmentCollection' )
406+ . returns ( mockSiteEnrollmentCollection ) ;
407+ } ) ;
408+
409+ it ( 'throws DataAccessError when productCode is falsy' , async ( ) => {
410+ await expect ( instance . allByEnrollmentProductCode ( '' ) ) . to . be . rejectedWith ( 'productCode is required' ) ;
411+ await expect ( instance . allByEnrollmentProductCode ( null ) ) . to . be . rejectedWith ( 'productCode is required' ) ;
412+ await expect ( instance . allByEnrollmentProductCode ( undefined ) ) . to . be . rejectedWith ( 'productCode is required' ) ;
413+ } ) ;
414+
415+ it ( 'returns empty array and does not call batchGetByKeys when no site IDs found' , async ( ) => {
416+ mockSiteEnrollmentCollection . allSiteIdsByProductCode . resolves ( [ ] ) ;
417+ instance . batchGetByKeys = stub ( ) ;
418+
419+ const result = await instance . allByEnrollmentProductCode ( 'LLMO' ) ;
420+
421+ expect ( result ) . to . deep . equal ( [ ] ) ;
422+ expect ( mockSiteEnrollmentCollection . allSiteIdsByProductCode ) . to . have . been . calledOnceWithExactly ( 'LLMO' ) ;
423+ expect ( instance . batchGetByKeys ) . to . not . have . been . called ;
424+ } ) ;
425+
426+ it ( 'returns sites fetched by batchGetByKeys with default empty options' , async ( ) => {
427+ const siteIds = [ 'cfa88998-a0a0-4136-b21d-0ff2aa127443' , 'd1e2f3a4-b5c6-7890-abcd-ef1234567890' ] ;
428+ const mockSites = [ { getId : ( ) => siteIds [ 0 ] } , { getId : ( ) => siteIds [ 1 ] } ] ;
429+ mockSiteEnrollmentCollection . allSiteIdsByProductCode . resolves ( siteIds ) ;
430+ instance . batchGetByKeys = stub ( ) . resolves ( { data : mockSites } ) ;
431+
432+ const result = await instance . allByEnrollmentProductCode ( 'LLMO' ) ;
433+
434+ expect ( result ) . to . deep . equal ( mockSites ) ;
435+ expect ( instance . batchGetByKeys ) . to . have . been . calledOnceWithExactly (
436+ [
437+ { siteId : 'cfa88998-a0a0-4136-b21d-0ff2aa127443' } ,
438+ { siteId : 'd1e2f3a4-b5c6-7890-abcd-ef1234567890' } ,
439+ ] ,
440+ { } ,
441+ ) ;
442+ } ) ;
443+
444+ it ( 'passes caller-supplied options through to batchGetByKeys' , async ( ) => {
445+ const siteIds = [ 'cfa88998-a0a0-4136-b21d-0ff2aa127443' ] ;
446+ const mockSites = [ { getId : ( ) => siteIds [ 0 ] } ] ;
447+ const options = { attributes : [ 'siteId' , 'baseURL' , 'config' ] } ;
448+ mockSiteEnrollmentCollection . allSiteIdsByProductCode . resolves ( siteIds ) ;
449+ instance . batchGetByKeys = stub ( ) . resolves ( { data : mockSites } ) ;
450+
451+ const result = await instance . allByEnrollmentProductCode ( 'LLMO' , options ) ;
452+
453+ expect ( result ) . to . deep . equal ( mockSites ) ;
454+ expect ( instance . batchGetByKeys ) . to . have . been . calledOnceWithExactly (
455+ [ { siteId : 'cfa88998-a0a0-4136-b21d-0ff2aa127443' } ] ,
456+ options ,
457+ ) ;
458+ } ) ;
459+ } ) ;
396460} ) ;
0 commit comments