Skip to content

Commit

Permalink
Merge branch 'main' into selectable-button
Browse files Browse the repository at this point in the history
Signed-off-by: Yuanqi(Ella) Zhu <[email protected]>
  • Loading branch information
zhyuanqi authored Apr 16, 2024
2 parents a78a8e7 + a1c8b8c commit 75445e7
Show file tree
Hide file tree
Showing 21 changed files with 497 additions and 42 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [CSP Handler] Update CSP handler to only query and modify frame ancestors instead of all CSP directives ([#6398](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6398))
- [MD] Add OpenSearch cluster group label to top of single selectable dropdown ([#6400](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6400))
- [Workspace] Support workspace in saved objects client in server side. ([#6365](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6365))
- [MD] Add dropdown header to data source single selector ([#6431](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6431))

### 🐛 Bug Fixes

Expand Down Expand Up @@ -119,7 +120,9 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [BUG][Multiple Datasource] Refactor read-only component to cover more edge cases ([#6416](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6416))
- [BUG] Fix for checkForFunctionProperty so that order does not matter ([#6248](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6248))
- [BUG][Multiple Datasource] Modify the button of selectable component to fix the title overflow issue ([#6465](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6465))
- [Dynamic Configurations] Fix dynamic config API calls to pass correct input ([#6474](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6474))
- [BUG][Multiple Datasource] Validation succeed as long as status code in response is 200 ([#6399](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6399))
- [BUG][Multiple Datasource] Add validation for title length to be no longer than 32 characters [#6452](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6452))

### 🚞 Infrastructure

Expand Down
86 changes: 78 additions & 8 deletions src/plugins/application_config/server/routes/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ describe('application config routes', () => {
getConfig: jest.fn().mockReturnValue(configurations),
};

const getConfigurationClient = jest.fn().mockReturnValue(client);

const request = {};

const okResponse = {
Expand All @@ -91,7 +93,12 @@ describe('application config routes', () => {

const logger = loggerMock.create();

const returnedResponse = await handleGetConfig(client, request, response, logger);
const returnedResponse = await handleGetConfig(
getConfigurationClient,
request,
response,
logger
);

expect(returnedResponse).toBe(okResponse);

Expand All @@ -100,6 +107,8 @@ describe('application config routes', () => {
value: configurations,
},
});

expect(getConfigurationClient).toBeCalledWith(request);
});

it('return error response when client throws error', async () => {
Expand All @@ -111,6 +120,8 @@ describe('application config routes', () => {
}),
};

const getConfigurationClient = jest.fn().mockReturnValue(client);

const request = {};

const response = {
Expand All @@ -119,7 +130,12 @@ describe('application config routes', () => {

const logger = loggerMock.create();

const returnedResponse = await handleGetConfig(client, request, response, logger);
const returnedResponse = await handleGetConfig(
getConfigurationClient,
request,
response,
logger
);

expect(returnedResponse).toBe(ERROR_RESPONSE);

Expand All @@ -131,6 +147,7 @@ describe('application config routes', () => {
});

expect(logger.error).toBeCalledWith(error);
expect(getConfigurationClient).toBeCalledWith(request);
});
});

Expand All @@ -140,6 +157,8 @@ describe('application config routes', () => {
getEntityConfig: jest.fn().mockReturnValue(ENTITY_VALUE),
};

const getConfigurationClient = jest.fn().mockReturnValue(client);

const okResponse = {
statusCode: 200,
};
Expand All @@ -156,7 +175,12 @@ describe('application config routes', () => {

const logger = loggerMock.create();

const returnedResponse = await handleGetEntityConfig(client, request, response, logger);
const returnedResponse = await handleGetEntityConfig(
getConfigurationClient,
request,
response,
logger
);

expect(returnedResponse).toBe(okResponse);

Expand All @@ -165,6 +189,8 @@ describe('application config routes', () => {
value: ENTITY_VALUE,
},
});

expect(getConfigurationClient).toBeCalledWith(request);
});

it('return error response when client throws error', async () => {
Expand All @@ -176,6 +202,8 @@ describe('application config routes', () => {
}),
};

const getConfigurationClient = jest.fn().mockReturnValue(client);

const request = {
params: {
entity: ENTITY_NAME,
Expand All @@ -188,7 +216,12 @@ describe('application config routes', () => {

const logger = loggerMock.create();

const returnedResponse = await handleGetEntityConfig(client, request, response, logger);
const returnedResponse = await handleGetEntityConfig(
getConfigurationClient,
request,
response,
logger
);

expect(returnedResponse).toBe(ERROR_RESPONSE);

Expand All @@ -200,6 +233,8 @@ describe('application config routes', () => {
});

expect(logger.error).toBeCalledWith(error);

expect(getConfigurationClient).toBeCalledWith(request);
});
});

Expand All @@ -209,6 +244,8 @@ describe('application config routes', () => {
updateEntityConfig: jest.fn().mockReturnValue(ENTITY_NEW_VALUE),
};

const getConfigurationClient = jest.fn().mockReturnValue(client);

const okResponse = {
statusCode: 200,
};
Expand All @@ -228,7 +265,12 @@ describe('application config routes', () => {

const logger = loggerMock.create();

const returnedResponse = await handleUpdateEntityConfig(client, request, response, logger);
const returnedResponse = await handleUpdateEntityConfig(
getConfigurationClient,
request,
response,
logger
);

expect(returnedResponse).toBe(okResponse);

Expand All @@ -241,6 +283,8 @@ describe('application config routes', () => {
});

expect(logger.error).not.toBeCalled();

expect(getConfigurationClient).toBeCalledWith(request);
});

it('return error response when client fails', async () => {
Expand All @@ -252,6 +296,8 @@ describe('application config routes', () => {
}),
};

const getConfigurationClient = jest.fn().mockReturnValue(client);

const request = {
params: {
entity: ENTITY_NAME,
Expand All @@ -267,7 +313,12 @@ describe('application config routes', () => {

const logger = loggerMock.create();

const returnedResponse = await handleUpdateEntityConfig(client, request, response, logger);
const returnedResponse = await handleUpdateEntityConfig(
getConfigurationClient,
request,
response,
logger
);

expect(returnedResponse).toBe(ERROR_RESPONSE);

Expand All @@ -279,6 +330,8 @@ describe('application config routes', () => {
});

expect(logger.error).toBeCalledWith(error);

expect(getConfigurationClient).toBeCalledWith(request);
});
});

Expand All @@ -288,6 +341,8 @@ describe('application config routes', () => {
deleteEntityConfig: jest.fn().mockReturnValue(ENTITY_NAME),
};

const getConfigurationClient = jest.fn().mockReturnValue(client);

const okResponse = {
statusCode: 200,
};
Expand All @@ -304,7 +359,12 @@ describe('application config routes', () => {

const logger = loggerMock.create();

const returnedResponse = await handleDeleteEntityConfig(client, request, response, logger);
const returnedResponse = await handleDeleteEntityConfig(
getConfigurationClient,
request,
response,
logger
);

expect(returnedResponse).toBe(okResponse);

Expand All @@ -317,6 +377,7 @@ describe('application config routes', () => {
});

expect(logger.error).not.toBeCalled();
expect(getConfigurationClient).toBeCalledWith(request);
});

it('return error response when client fails', async () => {
Expand All @@ -328,6 +389,8 @@ describe('application config routes', () => {
}),
};

const getConfigurationClient = jest.fn().mockReturnValue(client);

const request = {
params: {
entity: ENTITY_NAME,
Expand All @@ -340,7 +403,12 @@ describe('application config routes', () => {

const logger = loggerMock.create();

const returnedResponse = await handleDeleteEntityConfig(client, request, response, logger);
const returnedResponse = await handleDeleteEntityConfig(
getConfigurationClient,
request,
response,
logger
);

expect(returnedResponse).toBe(ERROR_RESPONSE);

Expand All @@ -352,6 +420,8 @@ describe('application config routes', () => {
});

expect(logger.error).toBeCalledWith(error);

expect(getConfigurationClient).toBeCalledWith(request);
});
});
});
35 changes: 17 additions & 18 deletions src/plugins/application_config/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import { schema } from '@osd/config-schema';
import {
IRouter,
IScopedClusterClient,
Logger,
OpenSearchDashboardsRequest,
OpenSearchDashboardsResponseFactory,
Expand All @@ -15,7 +14,7 @@ import { ConfigurationClient } from '../types';

export function defineRoutes(
router: IRouter,
getConfigurationClient: (configurationClient: IScopedClusterClient) => ConfigurationClient,
getConfigurationClient: (request?: OpenSearchDashboardsRequest) => ConfigurationClient,
logger: Logger
) {
router.get(
Expand All @@ -24,9 +23,7 @@ export function defineRoutes(
validate: false,
},
async (context, request, response) => {
const client = getConfigurationClient(context.core.opensearch.client);

return await handleGetConfig(client, request, response, logger);
return await handleGetConfig(getConfigurationClient, request, response, logger);
}
);
router.get(
Expand All @@ -39,9 +36,7 @@ export function defineRoutes(
},
},
async (context, request, response) => {
const client = getConfigurationClient(context.core.opensearch.client);

return await handleGetEntityConfig(client, request, response, logger);
return await handleGetEntityConfig(getConfigurationClient, request, response, logger);
}
);
router.post(
Expand All @@ -57,9 +52,7 @@ export function defineRoutes(
},
},
async (context, request, response) => {
const client = getConfigurationClient(context.core.opensearch.client);

return await handleUpdateEntityConfig(client, request, response, logger);
return await handleUpdateEntityConfig(getConfigurationClient, request, response, logger);
}
);
router.delete(
Expand All @@ -72,21 +65,21 @@ export function defineRoutes(
},
},
async (context, request, response) => {
const client = getConfigurationClient(context.core.opensearch.client);

return await handleDeleteEntityConfig(client, request, response, logger);
return await handleDeleteEntityConfig(getConfigurationClient, request, response, logger);
}
);
}

export async function handleGetEntityConfig(
client: ConfigurationClient,
getConfigurationClient: (request?: OpenSearchDashboardsRequest) => ConfigurationClient,
request: OpenSearchDashboardsRequest,
response: OpenSearchDashboardsResponseFactory,
logger: Logger
) {
logger.info(`Received a request to get entity config for ${request.params.entity}.`);

const client = getConfigurationClient(request);

try {
const result = await client.getEntityConfig(request.params.entity, {
headers: request.headers,
Expand All @@ -103,7 +96,7 @@ export async function handleGetEntityConfig(
}

export async function handleUpdateEntityConfig(
client: ConfigurationClient,
getConfigurationClient: (request?: OpenSearchDashboardsRequest) => ConfigurationClient,
request: OpenSearchDashboardsRequest,
response: OpenSearchDashboardsResponseFactory,
logger: Logger
Expand All @@ -112,6 +105,8 @@ export async function handleUpdateEntityConfig(
`Received a request to update entity ${request.params.entity} with new value ${request.body.newValue}.`
);

const client = getConfigurationClient(request);

try {
const result = await client.updateEntityConfig(request.params.entity, request.body.newValue, {
headers: request.headers,
Expand All @@ -128,13 +123,15 @@ export async function handleUpdateEntityConfig(
}

export async function handleDeleteEntityConfig(
client: ConfigurationClient,
getConfigurationClient: (request?: OpenSearchDashboardsRequest) => ConfigurationClient,
request: OpenSearchDashboardsRequest,
response: OpenSearchDashboardsResponseFactory,
logger: Logger
) {
logger.info(`Received a request to delete entity ${request.params.entity}.`);

const client = getConfigurationClient(request);

try {
const result = await client.deleteEntityConfig(request.params.entity, {
headers: request.headers,
Expand All @@ -151,13 +148,15 @@ export async function handleDeleteEntityConfig(
}

export async function handleGetConfig(
client: ConfigurationClient,
getConfigurationClient: (request?: OpenSearchDashboardsRequest) => ConfigurationClient,
request: OpenSearchDashboardsRequest,
response: OpenSearchDashboardsResponseFactory,
logger: Logger
) {
logger.info('Received a request to get all configurations.');

const client = getConfigurationClient(request);

try {
const result = await client.getConfig({ headers: request.headers });
return response.ok({
Expand Down
Loading

0 comments on commit 75445e7

Please sign in to comment.