Skip to content

Commit

Permalink
EMT-146: add more documentation and test
Browse files Browse the repository at this point in the history
  • Loading branch information
nnamdifrankie committed Apr 21, 2020
1 parent e990c47 commit 2bd6601
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions x-pack/plugins/ingest_manager/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ import { AgentStatus } from './models';
export * from './models';
export * from './rest_spec';

/**
* A service that provides exported functions that return information about an Agent
*/
export interface AgentService {
/**
* Return the status by the Agent's id
* @param soClient
* @param agentId
*/
getAgentStatusById(soClient: SavedObjectsClientContract, agentId: string): Promise<AgentStatus>;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { savedObjectsClientMock } from '../../../../../../src/core/server/saved_objects/service/saved_objects_client.mock';
import { getAgentStatusById } from './status';
import { AGENT_TYPE_PERMANENT } from '../../../common/constants';
import { AgentSOAttributes } from '../../../common/types/models';
import { SavedObject } from 'kibana/server';

describe('Agent status service', () => {
it('should return inactive when agent is not active', async () => {
const mockSavedObjectsClient = savedObjectsClientMock.create();
mockSavedObjectsClient.get = jest.fn().mockReturnValue({
id: 'id',
type: AGENT_TYPE_PERMANENT,
attributes: {
active: false,
local_metadata: '{}',
user_provided_metadata: '{}',
},
} as SavedObject<AgentSOAttributes>);
const status = await getAgentStatusById(mockSavedObjectsClient, 'id');
expect(status).toEqual('inactive');
});

it('should return online when agent is active', async () => {
const mockSavedObjectsClient = savedObjectsClientMock.create();
mockSavedObjectsClient.get = jest.fn().mockReturnValue({
id: 'id',
type: AGENT_TYPE_PERMANENT,
attributes: {
active: true,
local_metadata: '{}',
user_provided_metadata: '{}',
},
} as SavedObject<AgentSOAttributes>);
const status = await getAgentStatusById(mockSavedObjectsClient, 'id');
expect(status).toEqual('online');
});
});

0 comments on commit 2bd6601

Please sign in to comment.