Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -220,34 +220,74 @@ describe('saved query route handler context', () => {
});

describe('update', function () {
it('should update a saved object for the given attributes', async () => {
const mockResponse: SavedObject<InternalSavedQueryAttributes> = {
id: 'foo',
type: 'query',
attributes: internalSavedQueryAttributes,
references: [],
};
beforeEach(() => {
mockSavedObjectsClient.find.mockResolvedValue({
total: 0,
page: 0,
per_page: 0,
saved_objects: [],
});
mockSavedObjectsClient.update.mockResolvedValue(mockResponse);
});

describe('when the saved query does not have namespaces', () => {
it('should update a saved object for the given attributes', async () => {
// Given
const mockResponse: SavedObject<InternalSavedQueryAttributes> = {
id: 'foo',
type: 'query',
attributes: internalSavedQueryAttributes,
references: [],
};
mockSavedObjectsClient.update.mockResolvedValue(mockResponse);

const response = await context.update('foo', savedQueryAttributes);
// When
const response = await context.update('foo', savedQueryAttributes);

expect(mockSavedObjectsClient.update).toHaveBeenCalledWith(
'query',
'foo',
{ ...internalSavedQueryAttributes, timefilter: null },
{
// Then
expect(mockSavedObjectsClient.update).toHaveBeenCalledWith(
'query',
'foo',
{ ...internalSavedQueryAttributes, timefilter: null },
{
references: [],
}
);
expect(response).toEqual({
id: 'foo',
attributes: savedQueryAttributes,
});
});
});

describe('when the saved query has namespaces', () => {
it('should update a saved object for the given attributes', async () => {
// Given
const mockResponse: SavedObject<InternalSavedQueryAttributes> = {
id: 'foo',
type: 'query',
attributes: internalSavedQueryAttributes,
references: [],
}
);
expect(response).toEqual({
id: 'foo',
attributes: savedQueryAttributes,
namespaces: ['default'],
};
mockSavedObjectsClient.update.mockResolvedValue(mockResponse);

// When
const response = await context.update('foo', savedQueryAttributes);

// Then
expect(mockSavedObjectsClient.update).toHaveBeenCalledWith(
'query',
'foo',
{ ...internalSavedQueryAttributes, timefilter: null },
{
references: [],
}
);
expect(response).toEqual({
id: 'foo',
attributes: savedQueryAttributes,
namespaces: ['default'],
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export async function registerSavedQueryRouteHandlerContext(context: RequestHand
// TODO: Handle properly
if (savedObject.error) throw internal(savedObject.error.message);

return injectReferences({ id, attributes, references });
return injectReferences({ id, attributes, references, namespaces: savedObject.namespaces });
};

const getSavedQuery = async (id: string): Promise<SavedQueryRestResponse> => {
Expand Down