Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkime committed Sep 21, 2021
1 parent 1a2d9a6 commit 394c811
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { SavedObjectsClientPublicToCommon } from './saved_objects_client_wrapper';
import { savedObjectsServiceMock } from 'src/core/public/mocks';

import { DataViewSavedObjectConflictError } from '../../common/data_views';

describe('SavedObjectsClientPublicToCommon', () => {
const soClient = savedObjectsServiceMock.createStartContract().client;

test('get saved object - exactMatch', async () => {
const mockedSavedObject = {
version: 'abc',
};
soClient.resolve = jest
.fn()
.mockResolvedValue({ outcome: 'exactMatch', saved_object: mockedSavedObject });
const service = new SavedObjectsClientPublicToCommon(soClient);
const result = await service.get('index-pattern', '1');
expect(result).toStrictEqual(mockedSavedObject);
});

test('get saved object - aliasMatch', async () => {
const mockedSavedObject = {
version: 'def',
};
soClient.resolve = jest
.fn()
.mockResolvedValue({ outcome: 'aliasMatch', saved_object: mockedSavedObject });
const service = new SavedObjectsClientPublicToCommon(soClient);
const result = await service.get('index-pattern', '1');
expect(result).toStrictEqual(mockedSavedObject);
});

test('get saved object - conflict', async () => {
const mockedSavedObject = {
version: 'ghi',
};

soClient.resolve = jest
.fn()
.mockResolvedValue({ outcome: 'conflict', saved_object: mockedSavedObject });
const service = new SavedObjectsClientPublicToCommon(soClient);

await expect(service.get('index-pattern', '1')).rejects.toThrow(
DataViewSavedObjectConflictError
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { SavedObjectsClientServerToCommon } from './saved_objects_client_wrapper';
import { SavedObjectsClientContract } from 'src/core/server';

import { DataViewSavedObjectConflictError } from '../../common/data_views';

describe('SavedObjectsClientPublicToCommon', () => {
const soClient = ({ resolve: jest.fn() } as unknown) as SavedObjectsClientContract;

test('get saved object - exactMatch', async () => {
const mockedSavedObject = {
version: 'abc',
};
soClient.resolve = jest
.fn()
.mockResolvedValue({ outcome: 'exactMatch', saved_object: mockedSavedObject });
const service = new SavedObjectsClientServerToCommon(soClient);
const result = await service.get('index-pattern', '1');
expect(result).toStrictEqual(mockedSavedObject);
});

test('get saved object - aliasMatch', async () => {
const mockedSavedObject = {
version: 'def',
};
soClient.resolve = jest
.fn()
.mockResolvedValue({ outcome: 'aliasMatch', saved_object: mockedSavedObject });
const service = new SavedObjectsClientServerToCommon(soClient);
const result = await service.get('index-pattern', '1');
expect(result).toStrictEqual(mockedSavedObject);
});

test('get saved object - conflict', async () => {
const mockedSavedObject = {
version: 'ghi',
};

soClient.resolve = jest
.fn()
.mockResolvedValue({ outcome: 'conflict', saved_object: mockedSavedObject });
const service = new SavedObjectsClientServerToCommon(soClient);

await expect(service.get('index-pattern', '1')).rejects.toThrow(
DataViewSavedObjectConflictError
);
});
});

0 comments on commit 394c811

Please sign in to comment.