@@ -24,15 +24,23 @@ import {
2424import { xpackMocks } from '../../../../../../mocks' ;
2525import { ENDPOINT_TRUSTED_APPS_LIST_ID } from '../../../../../lists/common/constants' ;
2626import { EndpointAppContext } from '../../types' ;
27- import { ExceptionListClient } from '../../../../../lists/server' ;
28- import { getExceptionListItemSchemaMock } from '../../../../../lists/common/schemas/response/exception_list_item_schema.mock ' ;
27+ import { ExceptionListClient , ListClient } from '../../../../../lists/server' ;
28+ import { listMock } from '../../../../../lists/server/mocks ' ;
2929import { ExceptionListItemSchema } from '../../../../../lists/common/schemas/response' ;
3030import { DeleteTrustedAppsRequestParams } from './types' ;
31+ import { getExceptionListItemSchemaMock } from '../../../../../lists/common/schemas/response/exception_list_item_schema.mock' ;
32+
33+ type RequestHandlerContextWithLists = ReturnType < typeof xpackMocks . createRequestHandlerContext > & {
34+ lists ?: {
35+ getListClient : ( ) => jest . Mocked < ListClient > ;
36+ getExceptionListClient : ( ) => jest . Mocked < ExceptionListClient > ;
37+ } ;
38+ } ;
3139
3240describe ( 'when invoking endpoint trusted apps route handlers' , ( ) => {
3341 let routerMock : jest . Mocked < IRouter > ;
3442 let endpointAppContextService : EndpointAppContextService ;
35- let context : ReturnType < typeof xpackMocks . createRequestHandlerContext > ;
43+ let context : RequestHandlerContextWithLists ;
3644 let response : ReturnType < typeof httpServerMock . createResponseFactory > ;
3745 let exceptionsListClient : jest . Mocked < ExceptionListClient > ;
3846 let endpointAppContext : EndpointAppContext ;
@@ -41,7 +49,7 @@ describe('when invoking endpoint trusted apps route handlers', () => {
4149 routerMock = httpServiceMock . createRouter ( ) ;
4250 endpointAppContextService = new EndpointAppContextService ( ) ;
4351 const startContract = createMockEndpointAppContextServiceStartContract ( ) ;
44- exceptionsListClient = startContract . exceptionsListService as jest . Mocked < ExceptionListClient > ;
52+ exceptionsListClient = listMock . getExceptionListClient ( ) as jest . Mocked < ExceptionListClient > ;
4553 endpointAppContextService . start ( startContract ) ;
4654 endpointAppContext = {
4755 ...createMockEndpointAppContext ( ) ,
@@ -50,7 +58,13 @@ describe('when invoking endpoint trusted apps route handlers', () => {
5058 registerTrustedAppsRoutes ( routerMock , endpointAppContext ) ;
5159
5260 // For use in individual API calls
53- context = xpackMocks . createRequestHandlerContext ( ) ;
61+ context = {
62+ ...xpackMocks . createRequestHandlerContext ( ) ,
63+ lists : {
64+ getListClient : jest . fn ( ) ,
65+ getExceptionListClient : jest . fn ( ) . mockReturnValue ( exceptionsListClient ) ,
66+ } ,
67+ } ;
5468 response = httpServerMock . createResponseFactory ( ) ;
5569 } ) ;
5670
@@ -74,6 +88,12 @@ describe('when invoking endpoint trusted apps route handlers', () => {
7488 ) ! ;
7589 } ) ;
7690
91+ it ( 'should use ExceptionListClient from route handler context' , async ( ) => {
92+ const request = createListRequest ( ) ;
93+ await routeHandler ( context , request , response ) ;
94+ expect ( context . lists ?. getExceptionListClient ) . toHaveBeenCalled ( ) ;
95+ } ) ;
96+
7797 it ( 'should create the Trusted Apps List first' , async ( ) => {
7898 const request = createListRequest ( ) ;
7999 await routeHandler ( context , request , response ) ;
@@ -155,6 +175,12 @@ describe('when invoking endpoint trusted apps route handlers', () => {
155175 } ) ;
156176 } ) ;
157177
178+ it ( 'should use ExceptionListClient from route handler context' , async ( ) => {
179+ const request = createPostRequest ( ) ;
180+ await routeHandler ( context , request , response ) ;
181+ expect ( context . lists ?. getExceptionListClient ) . toHaveBeenCalled ( ) ;
182+ } ) ;
183+
158184 it ( 'should create trusted app list first' , async ( ) => {
159185 const request = createPostRequest ( ) ;
160186 await routeHandler ( context , request , response ) ;
@@ -238,6 +264,11 @@ describe('when invoking endpoint trusted apps route handlers', () => {
238264 } ) ;
239265 } ) ;
240266
267+ it ( 'should use ExceptionListClient from route handler context' , async ( ) => {
268+ await routeHandler ( context , request , response ) ;
269+ expect ( context . lists ?. getExceptionListClient ) . toHaveBeenCalled ( ) ;
270+ } ) ;
271+
241272 it ( 'should return 200 on successful delete' , async ( ) => {
242273 await routeHandler ( context , request , response ) ;
243274 expect ( exceptionsListClient . deleteExceptionListItem ) . toHaveBeenCalledWith ( {
0 commit comments