File tree Expand file tree Collapse file tree 2 files changed +30
-9
lines changed
Expand file tree Collapse file tree 2 files changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -132,25 +132,34 @@ describe('healthController', () => {
132132 const res = createRes ( ) ;
133133 await healthController . getEmbedDomains ( { query : { } } as unknown as Request , res ) ;
134134
135- expect ( res . status ) . toHaveBeenCalledWith ( 503 ) ;
135+ expect ( res . status ) . toHaveBeenCalledWith ( 200 ) ;
136136 expect ( res . json ) . toHaveBeenCalledWith ( {
137- status : 'error ' ,
137+ status : 'success ' ,
138138 domains : [
139139 {
140140 name : 'VIDSRC_DOMAIN' ,
141141 domain : 'vidsrc.example' ,
142142 status : 'success' ,
143143 httpStatus : 200 ,
144144 } ,
145- {
146- name : 'MULTI_DOMAIN' ,
147- status : 'error' ,
148- message : 'Domain not configured' ,
149- } ,
150145 ] ,
151146 } ) ;
152147 } ) ;
153148
149+ test ( 'getEmbedDomains rejects multi target when MULTI_DOMAIN is not configured' , async ( ) => {
150+ ( appConfig as any ) . MULTI_DOMAIN = undefined ;
151+ const res = createRes ( ) ;
152+
153+ await healthController . getEmbedDomains ( { query : { target : 'multi' } } as unknown as Request , res ) ;
154+
155+ expect ( res . status ) . toHaveBeenCalledWith ( 400 ) ;
156+ expect ( res . json ) . toHaveBeenCalledWith ( {
157+ status : 'error' ,
158+ message : 'Target not configured' ,
159+ domains : [ ] ,
160+ } ) ;
161+ } ) ;
162+
154163 test ( 'getEmbedDomains filters by target query and returns 200 when healthy' , async ( ) => {
155164 mockedHttpClient . get . mockResolvedValue ( { status : 200 } as any ) ;
156165
Original file line number Diff line number Diff line change @@ -82,18 +82,30 @@ const healthController = {
8282 * @param {Request } _req - Express request object.
8383 * @param {Response } res - Express response object.
8484 * @returns {Promise<Response> } JSON response containing domain health information.
85- */
85+ */
8686 async getEmbedDomains ( req : Request , res : Response ) : Promise < Response > {
8787 const target = typeof req . query . target === 'string' ? req . query . target . toLowerCase ( ) : undefined ;
8888
89+ // Return 400 if there is no `MULTI_DOMAIN` configured
90+ if ( target === 'multi' && ! appConfig . MULTI_DOMAIN ) {
91+ return res . status ( 400 ) . json ( {
92+ status : 'error' ,
93+ message : 'Target not configured' ,
94+ domains : [ ] ,
95+ } ) ;
96+ }
97+
8998 const checks : Array < Promise < DomainHealthResult > > = [ ] ;
9099
91100 if ( ! target || target === 'vidsrc' ) {
92101 checks . push ( checkDomainHealth ( 'VIDSRC_DOMAIN' , appConfig . VIDSRC_DOMAIN ) ) ;
93102 }
94103
95104 if ( ! target || target === 'multi' ) {
96- checks . push ( checkDomainHealth ( 'MULTI_DOMAIN' , appConfig . MULTI_DOMAIN ) ) ;
105+ // This makes sure we make this optional as there will be scenarios where MULTI_DOMAIN isn't configured
106+ if ( appConfig . MULTI_DOMAIN ) {
107+ checks . push ( checkDomainHealth ( 'MULTI_DOMAIN' , appConfig . MULTI_DOMAIN ) ) ;
108+ }
97109 }
98110
99111 if ( checks . length === 0 ) {
You can’t perform that action at this time.
0 commit comments