Skip to content

Commit 900816b

Browse files
committed
Use constants
Signed-off-by: Derek Ho <dxho@amazon.com>
1 parent 544947a commit 900816b

File tree

3 files changed

+61
-33
lines changed

3 files changed

+61
-33
lines changed

common/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515

1616
export const PLUGIN_ID = 'opensearchDashboardsSecurity';
1717
export const PLUGIN_NAME = 'security-dashboards-plugin';
18+
export const PLUGIN_GET_STARTED_APP_ID = 'security-dashboards-plugin_getstarted';
19+
export const PLUGIN_AUTH_APP_ID = 'security-dashboards-plugin_auth';
20+
export const PLUGIN_ROLES_APP_ID = 'security-dashboards-plugin_roles';
21+
export const PLUGIN_USERS_APP_ID = 'security-dashboards-plugin_users';
22+
export const PLUGIN_PERMISSIONS_APP_ID = 'security-dashboards-plugin_permissions';
23+
export const PLUGIN_TENANTS_APP_ID = 'security-dashboards-plugin_tenants';
24+
export const PLUGIN_AUDITLOG_APP_ID = 'security-dashboards-plugin_auditlog';
1825

1926
export const APP_ID_LOGIN = 'login';
2027
export const APP_ID_CUSTOMERROR = 'customerror';

public/plugin.ts

+27-15
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,19 @@ import {
3030
PluginInitializerContext,
3131
WorkspaceAvailability,
3232
} from '../../../src/core/public';
33-
import { APP_ID_LOGIN, CUSTOM_ERROR_PAGE_URI, LOGIN_PAGE_URI, PLUGIN_NAME } from '../common';
33+
import {
34+
APP_ID_LOGIN,
35+
CUSTOM_ERROR_PAGE_URI,
36+
LOGIN_PAGE_URI,
37+
PLUGIN_AUDITLOG_APP_ID,
38+
PLUGIN_AUTH_APP_ID,
39+
PLUGIN_GET_STARTED_APP_ID,
40+
PLUGIN_NAME,
41+
PLUGIN_PERMISSIONS_APP_ID,
42+
PLUGIN_ROLES_APP_ID,
43+
PLUGIN_TENANTS_APP_ID,
44+
PLUGIN_USERS_APP_ID,
45+
} from '../common';
3446
import { APP_ID_CUSTOMERROR } from '../common';
3547
import { setupTopNavButton } from './apps/account/account-app';
3648
import { fetchAccountInfoSafe } from './apps/account/utils';
@@ -175,7 +187,7 @@ export class SecurityPlugin
175187

176188
if (core.chrome.navGroup.getNavGroupEnabled()) {
177189
core.application.register({
178-
id: `security-dashboards-plugin_getstarted`,
190+
id: PLUGIN_GET_STARTED_APP_ID,
179191
title: 'Get Started',
180192
order: 8040,
181193
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
@@ -185,7 +197,7 @@ export class SecurityPlugin
185197
},
186198
});
187199
core.application.register({
188-
id: `security-dashboards-plugin_auth`,
200+
id: PLUGIN_AUTH_APP_ID,
189201
title: 'Authentication',
190202
order: 8040,
191203
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
@@ -195,7 +207,7 @@ export class SecurityPlugin
195207
},
196208
});
197209
core.application.register({
198-
id: `security-dashboards-plugin_roles`,
210+
id: PLUGIN_ROLES_APP_ID,
199211
title: 'Roles',
200212
order: 8040,
201213
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
@@ -205,7 +217,7 @@ export class SecurityPlugin
205217
},
206218
});
207219
core.application.register({
208-
id: `security-dashboards-plugin_users`,
220+
id: PLUGIN_USERS_APP_ID,
209221
title: 'Internal users',
210222
order: 8040,
211223
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
@@ -215,7 +227,7 @@ export class SecurityPlugin
215227
},
216228
});
217229
core.application.register({
218-
id: `security-dashboards-plugin_permissions`,
230+
id: PLUGIN_PERMISSIONS_APP_ID,
219231
title: 'Permissions',
220232
order: 8040,
221233
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
@@ -226,7 +238,7 @@ export class SecurityPlugin
226238
});
227239
if (config.multitenancy.enabled) {
228240
core.application.register({
229-
id: `security-dashboards-plugin_tenants`,
241+
id: PLUGIN_TENANTS_APP_ID,
230242
title: 'Tenants',
231243
order: 8040,
232244
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
@@ -237,7 +249,7 @@ export class SecurityPlugin
237249
});
238250
}
239251
core.application.register({
240-
id: `security-dashboards-plugin_auditlog`,
252+
id: PLUGIN_AUDITLOG_APP_ID,
241253
title: 'Audit logs',
242254
order: 8040,
243255
workspaceAvailability: WorkspaceAvailability.outsideWorkspace,
@@ -250,31 +262,31 @@ export class SecurityPlugin
250262

251263
core.chrome.navGroup.addNavLinksToGroup(DEFAULT_NAV_GROUPS.dataAdministration, [
252264
{
253-
id: `security-dashboards-plugin_getstarted`,
265+
id: PLUGIN_GET_STARTED_APP_ID,
254266
category: dataAccessUsersCategory,
255267
},
256268
{
257-
id: `security-dashboards-plugin_auth`,
269+
id: PLUGIN_AUTH_APP_ID,
258270
category: dataAccessUsersCategory,
259271
},
260272
{
261-
id: `security-dashboards-plugin_roles`,
273+
id: PLUGIN_ROLES_APP_ID,
262274
category: dataAccessUsersCategory,
263275
},
264276
{
265-
id: `security-dashboards-plugin_users`,
277+
id: PLUGIN_USERS_APP_ID,
266278
category: dataAccessUsersCategory,
267279
},
268280
{
269-
id: `security-dashboards-plugin_permissions`,
281+
id: PLUGIN_PERMISSIONS_APP_ID,
270282
category: dataAccessUsersCategory,
271283
},
272284
{
273-
id: `security-dashboards-plugin_tenants`,
285+
id: PLUGIN_TENANTS_APP_ID,
274286
category: dataAccessUsersCategory,
275287
},
276288
{
277-
id: `security-dashboards-plugin_auditlog`,
289+
id: PLUGIN_AUDITLOG_APP_ID,
278290
category: dataAccessUsersCategory,
279291
},
280292
]);

public/test/plugin.test.ts

+27-18
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@
4646
import { coreMock } from '../../../../src/core/public/mocks';
4747
import { SecurityPlugin } from '../plugin.ts';
4848
import * as pluginModule from '../plugin'; // Import the entire module to mock specific functions
49+
import {
50+
PLUGIN_AUDITLOG_APP_ID,
51+
PLUGIN_AUTH_APP_ID,
52+
PLUGIN_GET_STARTED_APP_ID,
53+
PLUGIN_PERMISSIONS_APP_ID,
54+
PLUGIN_ROLES_APP_ID,
55+
PLUGIN_TENANTS_APP_ID,
56+
PLUGIN_USERS_APP_ID,
57+
} from '../../common/index.ts';
4958

5059
// Mock the hasApiPermission function
5160
jest.mock('../plugin', () => {
@@ -106,13 +115,13 @@ describe('SecurityPlugin', () => {
106115
// Assert that the register function was not called for specific applications
107116
const registeredApps = registerSpy.mock.calls.map((call) => call[0].id);
108117
const expectedApps = [
109-
'security-dashboards-plugin_getstarted',
110-
'security-dashboards-plugin_auth',
111-
'security-dashboards-plugin_roles',
112-
'security-dashboards-plugin_users',
113-
'security-dashboards-plugin_permissions',
114-
'security-dashboards-plugin_tenants',
115-
'security-dashboards-plugin_auditlog',
118+
PLUGIN_GET_STARTED_APP_ID,
119+
PLUGIN_AUTH_APP_ID,
120+
PLUGIN_ROLES_APP_ID,
121+
PLUGIN_USERS_APP_ID,
122+
PLUGIN_PERMISSIONS_APP_ID,
123+
PLUGIN_TENANTS_APP_ID,
124+
PLUGIN_AUDITLOG_APP_ID,
116125
];
117126

118127
expectedApps.forEach((app) => {
@@ -141,13 +150,13 @@ describe('SecurityPlugin', () => {
141150
// Assert that the register function was called for specific applications
142151
const registeredApps = registerSpy.mock.calls.map((call) => call[0].id);
143152
const expectedApps = [
144-
'security-dashboards-plugin_getstarted',
145-
'security-dashboards-plugin_auth',
146-
'security-dashboards-plugin_roles',
147-
'security-dashboards-plugin_users',
148-
'security-dashboards-plugin_permissions',
149-
'security-dashboards-plugin_tenants',
150-
'security-dashboards-plugin_auditlog',
153+
PLUGIN_GET_STARTED_APP_ID,
154+
PLUGIN_AUTH_APP_ID,
155+
PLUGIN_ROLES_APP_ID,
156+
PLUGIN_USERS_APP_ID,
157+
PLUGIN_PERMISSIONS_APP_ID,
158+
PLUGIN_TENANTS_APP_ID,
159+
PLUGIN_AUDITLOG_APP_ID,
151160
];
152161

153162
expectedApps.forEach((app) => {
@@ -190,10 +199,10 @@ describe('SecurityPlugin', () => {
190199

191200
// Assert that the register function was not called for tenancy app
192201
const registeredApps = registerSpy.mock.calls.map((call) => call[0].id);
193-
const expectedApps = ['security-dashboards-plugin_tenants'];
194202

195-
expectedApps.forEach((app) => {
196-
expect(registeredApps).not.toContain(app);
197-
});
203+
expect(registeredApps).not.toContain(PLUGIN_TENANTS_APP_ID);
204+
205+
// Assert that other apps are registered because the feature flag is on
206+
expect(registeredApps).toContain(PLUGIN_GET_STARTED_APP_ID);
198207
});
199208
});

0 commit comments

Comments
 (0)