Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Workspace][Bug] Unable to copy assets to a workspace without assigning related data source #7690

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
optimize the code
Signed-off-by: yubonluo <[email protected]>
yubonluo committed Nov 11, 2024
commit 91fdbe6a8e6e1b15a55e3997e68f05305f7f36f7
18 changes: 14 additions & 4 deletions src/core/server/saved_objects/import/utils.test.ts
Original file line number Diff line number Diff line change
@@ -370,14 +370,16 @@ describe('findReferenceDataSourceForObject', () => {
type: 'non-data-source',
attributes: {},
},
{
id: '6',
references: [{ id: '7', type: 'index-pattern', name: '7' }],
type: 'non-data-source',
attributes: {},
},
];

const ObjectsMap = new Map(savedObjects.map((so) => [so.id, so]));

test('returns null if no references exist', () => {
expect(findReferenceDataSourceForObject(savedObjects[2], ObjectsMap)).toBeNull();
});

test('returns the data-source reference if it exists in the references', () => {
const result = findReferenceDataSourceForObject(savedObjects[0], ObjectsMap);
expect(result).toEqual({ id: '5', type: 'data-source', name: '5' });
@@ -387,11 +389,19 @@ describe('findReferenceDataSourceForObject', () => {
expect(findReferenceDataSourceForObject(savedObjects[1], ObjectsMap)).toBeNull();
});

test('returns null if no references exist', () => {
expect(findReferenceDataSourceForObject(savedObjects[2], ObjectsMap)).toBeNull();
});

test('returns nested data-source reference if found', () => {
const result = findReferenceDataSourceForObject(savedObjects[3], ObjectsMap);
expect(result).toEqual({ id: '5', type: 'data-source', name: '5' });
});

test('returns null if the nested references have no data-source reference', () => {
expect(findReferenceDataSourceForObject(savedObjects[4], ObjectsMap)).toBeNull();
});

test('returns null if circular reference', () => {
const circularAssets: Array<SavedObject<{ title?: string }>> = [
{
Original file line number Diff line number Diff line change
@@ -10,21 +10,21 @@ import * as utilsExports from './utils';

describe('validateDataSources', () => {
const savedObjectsClient = savedObjectsClientMock.create();
const errorAccumulator: SavedObjectsImportError[] = [
{
id: '1',
type: 'dashboards',
meta: {},
error: { type: 'missing_references', references: [] },
},
];
const workspaces = ['workspace-1'];

beforeEach(() => {
jest.resetAllMocks();
});

it('returns empty array if no valid objects', async () => {
const errorAccumulator: SavedObjectsImportError[] = [
{
id: '1',
type: 'dashboards',
meta: {},
error: { type: 'missing_references', references: [] },
},
];
const savedObjects = [{ id: '1', type: 'dashboards', attributes: {}, references: [] }];
const result = await validateDataSources(
savedObjects,
@@ -72,7 +72,7 @@ describe('validateDataSources', () => {
expect(result).toEqual([
{
error: {
dataSourceName: 'DataSource 2',
dataSource: 'data-source-2',
type: 'missing_data_source',
},
id: '1',
Loading