Skip to content

Commit

Permalink
Update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jillguyonnet committed Feb 12, 2024
1 parent 4172ff6 commit fed9195
Showing 1 changed file with 27 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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' } } });
});
});

0 comments on commit fed9195

Please sign in to comment.