From fed9195a079a4cba6c0b2f5fe112ae4206303b47 Mon Sep 17 00:00:00 2001 From: jillguyonnet Date: Mon, 12 Feb 2024 17:44:33 +0100 Subject: [PATCH] Update unit test --- .../routes/fleet_server_hosts/handler.test.ts | 46 +++++++++++-------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/x-pack/plugins/fleet/server/routes/fleet_server_hosts/handler.test.ts b/x-pack/plugins/fleet/server/routes/fleet_server_hosts/handler.test.ts index e65942a50c9345..bfcb91351af11a 100644 --- a/x-pack/plugins/fleet/server/routes/fleet_server_hosts/handler.test.ts +++ b/x-pack/plugins/fleet/server/routes/fleet_server_hosts/handler.test.ts @@ -33,14 +33,10 @@ describe('fleet server hosts handler', () => { jest .spyOn(fleetServerService, 'updateFleetServerHost') .mockResolvedValue({ id: 'host1' } as any); - jest.spyOn(fleetServerService, 'listFleetServerHosts').mockResolvedValue({ - items: [ - { id: SERVERLESS_DEFAULT_FLEET_SERVER_HOST_ID, host_urls: ['http://elasticsearch:9200'] }, - ] as any, - total: 1, - page: 1, - perPage: 1, - }); + jest.spyOn(fleetServerService, 'getFleetServerHost').mockResolvedValue({ + id: SERVERLESS_DEFAULT_FLEET_SERVER_HOST_ID, + host_urls: ['http://elasticsearch:9200'], + } as any); jest .spyOn(agentPolicyService, 'bumpAllAgentPoliciesForFleetServerHosts') .mockResolvedValue({} as any); @@ -118,17 +114,29 @@ describe('fleet server hosts handler', () => { expect(res).toEqual({ body: { item: { id: 'host1' } } }); }); - // it('should return ok on put in stateful if host url is different from default', async () => { - // jest - // .spyOn(appContextService, 'getCloud') - // .mockReturnValue({ isServerlessEnabled: false } as any); + it('should return ok on put in serverless if host urls are not passed', async () => { + jest.spyOn(appContextService, 'getCloud').mockReturnValue({ isServerlessEnabled: true } as any); - // const res = await putFleetServerHostHandler( - // mockContext, - // { body: { host_urls: ['http://localhost:8080'] }, params: { outputId: 'host1' } } as any, - // mockResponse as any - // ); + const res = await putFleetServerHostHandler( + mockContext, + { body: { name: ['Renamed'] }, params: { outputId: 'host1' } } as any, + mockResponse as any + ); - // expect(res).toEqual({ body: { item: { id: 'host1' } } }); - // }); + expect(res).toEqual({ body: { item: { id: 'host1' } } }); + }); + + it('should return ok on put in stateful if host url is different from default', async () => { + jest + .spyOn(appContextService, 'getCloud') + .mockReturnValue({ isServerlessEnabled: false } as any); + + const res = await putFleetServerHostHandler( + mockContext, + { body: { host_urls: ['http://localhost:8080'] }, params: { outputId: 'host1' } } as any, + mockResponse as any + ); + + expect(res).toEqual({ body: { item: { id: 'host1' } } }); + }); });