Skip to content

Commit

Permalink
Splits repository api unit tests into individual tests (#173218)
Browse files Browse the repository at this point in the history
## Summary

Structural cleanup of the `SavedObjectsRepository`, continued from where
#157154 left off.
This PR holds changes to `repository.test.ts`, and splits the api unit
tests into dedicated test files next to the api implementation.

### Tests
This PR does not alter test coverage, its primary aim is to improve
DevEx when it comes to SOR api unit testing. Hopefully, it'll make life
easier for everyone touching the code.

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
TinaHeiligers and kibanamachine committed Dec 13, 2023
1 parent 103ca85 commit 49267f3
Show file tree
Hide file tree
Showing 20 changed files with 4,882 additions and 3,687 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ helpers to have to pass all the parameters again.

### lib/apis/internals
I would call them 'utilities with business logic'. These are the 'big' chunks of logic called by the APIs.
E.g preflightCheckForCreate, internalBulkResolve and so on.
E.g preflightCheckForCreate, internalBulkResolve and so on.

### Unit tests
Unit tests should be kept close to the implementation. While not always possible to customize test fixtures and mocks completely, it is perfectly acceptible to duplicate code, with a focus on code coverage.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import {
mockTimestampFieldsWithCreated,
} from '../../test_helpers/repository.test.common';

// BEWARE: The SavedObjectClient depends on the implementation details of the SavedObjectsRepository
// so any breaking changes to this repository are considered breaking changes to the SavedObjectsClient.

interface ExpectedErrorResult {
Expand All @@ -65,7 +64,7 @@ interface ExpectedErrorResult {
error: Record<string, any>;
}

describe('SavedObjectsRepository', () => {
describe('#bulkCreate', () => {
let client: ReturnType<typeof elasticsearchClientMock.createElasticsearchClient>;
let repository: SavedObjectsRepository;
let migrator: ReturnType<typeof kibanaMigratorMock.create>;
Expand Down Expand Up @@ -135,7 +134,7 @@ describe('SavedObjectsRepository', () => {
references: [{ name: 'search_0', type: 'search', id: '123' }],
});

describe('#bulkCreate', () => {
describe('performBulkCreate', () => {
beforeEach(() => {
mockPreflightCheckForCreate.mockReset();
mockPreflightCheckForCreate.mockImplementation(({ objects }) => {
Expand Down
Loading

0 comments on commit 49267f3

Please sign in to comment.