From f0d2cee93d95a76ddb0dcd0a1ae223c7d56c74a1 Mon Sep 17 00:00:00 2001 From: aporss Date: Tue, 5 Nov 2024 17:09:24 +0000 Subject: [PATCH 1/2] ui - display all domains that reference current user Signed-off-by: aporss --- ui/src/__tests__/api.test.js | 4 +- .../domain/[domain]/domain-settings.test.js | 6 +-- .../pages/domain/[domain]/group.test.js | 6 +-- .../[domain]/group/[group]/members.test.js | 6 +-- .../[domain]/group/[group]/review.test.js | 6 +-- .../[domain]/group/[group]/roles.test.js | 6 +-- .../[domain]/group/[group]/settings.test.js | 6 +-- .../[domain]/group/[group]/tags.test.js | 6 +-- .../domain/[domain]/microsegmentation.test.js | 6 +-- .../pages/domain/[domain]/policy.test.js | 6 +-- .../[domain]/policy/[policy]/tags.test.js | 6 +-- .../pages/domain/[domain]/role.test.js | 6 +-- .../[domain]/role/[role]/members.test.js | 6 +-- .../[domain]/role/[role]/policy.test.js | 6 +-- .../[domain]/role/[role]/review.test.js | 6 +-- .../domain/[domain]/role/[role]/tags.test.js | 6 +-- .../pages/domain/[domain]/service.test.js | 6 +-- .../[service]/instance/dynamic.test.js | 7 +-- .../service/[service]/instance/static.test.js | 7 +-- .../[service]/microsegmentation.test.js | 6 +-- .../[domain]/service/[service]/tags.test.js | 6 +-- .../pages/domain/[domain]/tags.test.js | 6 +-- .../pages/domain/[domain]/template.test.js | 6 +-- .../pages/domain/[domain]/visibility.test.js | 6 +-- ui/src/__tests__/pages/domain/create.test.js | 6 +-- ui/src/__tests__/pages/domain/manage.test.js | 6 +-- .../__tests__/redux/reducers/domains.test.js | 9 ++-- ui/src/__tests__/redux/thunk/domains.test.js | 11 ++--- ui/src/__tests__/server/handlers/api.test.js | 23 +++++++-- ui/src/api.js | 6 +-- ui/src/mock/MockData.js | 33 +++++++++++++ .../domain/[domain]/group/[group]/roles.js | 1 - ui/src/redux/thunks/domains.js | 48 ++++++++++++++++++- 33 files changed, 162 insertions(+), 125 deletions(-) create mode 100644 ui/src/mock/MockData.js diff --git a/ui/src/__tests__/api.test.js b/ui/src/__tests__/api.test.js index 1ed2232d735..fd4838f83af 100644 --- a/ui/src/__tests__/api.test.js +++ b/ui/src/__tests__/api.test.js @@ -27,7 +27,7 @@ describe('Fetchr Client API Test', () => { describe('listUserDomains test', () => { it('listUserDomains test success', async () => { myDataService = { - name: 'domain-list', + name: 'domain-role-member', read: function (req, resource, params, config, callback) { callback(null, DATA); }, @@ -39,7 +39,7 @@ describe('Fetchr Client API Test', () => { }); it('listUserDomains test error', async () => { myDataServiceErr = { - name: 'domain-list', + name: 'domain-role-member', read: function (req, resource, params, config, callback) { callback({}, null); }, diff --git a/ui/src/__tests__/pages/domain/[domain]/domain-settings.test.js b/ui/src/__tests__/pages/domain/[domain]/domain-settings.test.js index 40bbbb14a6a..536342857ab 100644 --- a/ui/src/__tests__/pages/domain/[domain]/domain-settings.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/domain-settings.test.js @@ -21,6 +21,7 @@ import { } from '../../../../tests_utils/ComponentsTestUtils'; import MockApi from '../../../../mock/MockApi'; import { waitFor } from '@testing-library/react'; +import { listUserDomains_response } from '../../../../mock/MockData'; afterEach(() => { MockApi.cleanMockApi(); @@ -28,9 +29,6 @@ afterEach(() => { describe('DomainSettingsPage', () => { it('should render', async () => { - let domains = []; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); let query = { domain: 'dom', }; @@ -63,7 +61,7 @@ describe('DomainSettingsPage', () => { ), listUserDomains: jest.fn().mockReturnValue( new Promise((resolve, reject) => { - resolve(domains); + resolve(listUserDomains_response); }) ), }; diff --git a/ui/src/__tests__/pages/domain/[domain]/group.test.js b/ui/src/__tests__/pages/domain/[domain]/group.test.js index 15c8cec3797..526c38d325b 100644 --- a/ui/src/__tests__/pages/domain/[domain]/group.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/group.test.js @@ -21,6 +21,7 @@ import { mockAllDomainDataApiCalls, renderWithRedux, } from '../../../../tests_utils/ComponentsTestUtils'; +import { listUserDomains_response } from '../../../../mock/MockData'; afterEach(() => { MockApi.cleanMockApi(); @@ -34,9 +35,6 @@ describe('GroupPage', () => { }); afterEach(() => MockApi.cleanMockApi()); it('should render', async () => { - let domains = []; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); let query = { domain: 'dom', }; @@ -69,7 +67,7 @@ describe('GroupPage', () => { ), listUserDomains: jest.fn().mockReturnValue( new Promise((resolve, reject) => { - resolve(domains); + resolve(listUserDomains_response); }) ), getGroups: jest.fn().mockReturnValue( diff --git a/ui/src/__tests__/pages/domain/[domain]/group/[group]/members.test.js b/ui/src/__tests__/pages/domain/[domain]/group/[group]/members.test.js index 3df624a06ce..dcda3782eb1 100644 --- a/ui/src/__tests__/pages/domain/[domain]/group/[group]/members.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/group/[group]/members.test.js @@ -21,6 +21,7 @@ import { renderWithRedux, } from '../../../../../../tests_utils/ComponentsTestUtils'; import MockApi from '../../../../../../mock/MockApi'; +import { listUserDomains_response } from '../../../../../../mock/MockData'; afterEach(() => { MockApi.cleanMockApi(); @@ -28,9 +29,6 @@ afterEach(() => { describe('GroupMemberPage', () => { it('should render', async () => { - let domains = []; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); let query = { domain: 'dom', }; @@ -67,7 +65,7 @@ describe('GroupMemberPage', () => { ), listUserDomains: jest.fn().mockReturnValue( new Promise((resolve, reject) => { - resolve(domains); + resolve(listUserDomains_response); }) ), getDomainRoleMembers: jest diff --git a/ui/src/__tests__/pages/domain/[domain]/group/[group]/review.test.js b/ui/src/__tests__/pages/domain/[domain]/group/[group]/review.test.js index 60318d22d01..ba286f2d33e 100644 --- a/ui/src/__tests__/pages/domain/[domain]/group/[group]/review.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/group/[group]/review.test.js @@ -21,6 +21,7 @@ import { renderWithRedux, } from '../../../../../../tests_utils/ComponentsTestUtils'; import MockApi from '../../../../../../mock/MockApi'; +import { listUserDomains_response } from '../../../../../../mock/MockData'; describe('GroupReviewPage', () => { beforeEach(() => { @@ -30,9 +31,6 @@ describe('GroupReviewPage', () => { }); afterEach(() => MockApi.cleanMockApi()); it('should render', async () => { - let domains = []; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); let query = { domain: 'dom', }; @@ -69,7 +67,7 @@ describe('GroupReviewPage', () => { ), listUserDomains: jest.fn().mockReturnValue( new Promise((resolve, reject) => { - resolve(domains); + resolve(listUserDomains_response); }) ), getGroup: jest.fn().mockReturnValue( diff --git a/ui/src/__tests__/pages/domain/[domain]/group/[group]/roles.test.js b/ui/src/__tests__/pages/domain/[domain]/group/[group]/roles.test.js index ee660038023..ddd0f2147ed 100644 --- a/ui/src/__tests__/pages/domain/[domain]/group/[group]/roles.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/group/[group]/roles.test.js @@ -21,6 +21,7 @@ import { mockAllDomainDataApiCalls, renderWithRedux, } from '../../../../../../tests_utils/ComponentsTestUtils'; +import { listUserDomains_response } from '../../../../../../mock/MockData'; afterEach(() => { MockApi.cleanMockApi(); @@ -28,9 +29,6 @@ afterEach(() => { describe('GroupRolesPage', () => { it('should render', async () => { - let domains = []; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); let query = { domain: 'dom', }; @@ -66,7 +64,7 @@ describe('GroupRolesPage', () => { ), listUserDomains: jest.fn().mockReturnValue( new Promise((resolve, reject) => { - resolve(domains); + resolve(listUserDomains_response); }) ), getGroup: jest.fn().mockReturnValue( diff --git a/ui/src/__tests__/pages/domain/[domain]/group/[group]/settings.test.js b/ui/src/__tests__/pages/domain/[domain]/group/[group]/settings.test.js index cd2cb5d5aa3..d0db42c6c4a 100644 --- a/ui/src/__tests__/pages/domain/[domain]/group/[group]/settings.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/group/[group]/settings.test.js @@ -21,6 +21,7 @@ import { mockAllDomainDataApiCalls, renderWithRedux, } from '../../../../../../tests_utils/ComponentsTestUtils'; +import { listUserDomains_response } from '../../../../../../mock/MockData'; afterEach(() => { MockApi.cleanMockApi(); @@ -29,9 +30,6 @@ afterEach(() => { describe('GroupSettingPage', () => { it('should render', async () => { let group = 'groupName'; - let domains = []; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); let query = { domain: 'dom', }; @@ -70,7 +68,7 @@ describe('GroupSettingPage', () => { ), listUserDomains: jest.fn().mockReturnValue( new Promise((resolve, reject) => { - resolve(domains); + resolve(listUserDomains_response); }) ), getGroup: jest.fn().mockReturnValue( diff --git a/ui/src/__tests__/pages/domain/[domain]/group/[group]/tags.test.js b/ui/src/__tests__/pages/domain/[domain]/group/[group]/tags.test.js index dbbed836e0f..39f3a9107c5 100644 --- a/ui/src/__tests__/pages/domain/[domain]/group/[group]/tags.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/group/[group]/tags.test.js @@ -25,6 +25,7 @@ import { configApiGroups, singleApiGroup, } from '../../../../../redux/config/group.test'; +import { listUserDomains_response } from '../../../../../../mock/MockData'; describe('Groups Tag Page', () => { afterEach(() => { @@ -34,9 +35,6 @@ describe('Groups Tag Page', () => { const query = { domain: 'dom', }; - let domains = []; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); const userId = 'test'; const domain = 'home.test'; const domainDetails = { @@ -77,7 +75,7 @@ describe('Groups Tag Page', () => { ), listUserDomains: jest.fn().mockReturnValue( new Promise((resolve, reject) => { - resolve(domains); + resolve(listUserDomains_response); }) ), getGroup: jest.fn().mockReturnValue( diff --git a/ui/src/__tests__/pages/domain/[domain]/microsegmentation.test.js b/ui/src/__tests__/pages/domain/[domain]/microsegmentation.test.js index 8d0596d18a2..c76a1e89dd9 100644 --- a/ui/src/__tests__/pages/domain/[domain]/microsegmentation.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/microsegmentation.test.js @@ -22,6 +22,7 @@ import { renderWithRedux, } from '../../../../tests_utils/ComponentsTestUtils'; import MockApi from '../../../../mock/MockApi'; +import { listUserDomains_response } from '../../../../mock/MockData'; afterEach(() => { MockApi.cleanMockApi(); @@ -29,9 +30,6 @@ afterEach(() => { describe('MicrosegmentationPage', () => { it('should render', async () => { - let domains = []; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); let query = { domain: 'dom', }; @@ -65,7 +63,7 @@ describe('MicrosegmentationPage', () => { ), listUserDomains: jest.fn().mockReturnValue( new Promise((resolve, reject) => { - resolve(domains); + resolve(listUserDomains_response); }) ), getPolicies: jest.fn().mockReturnValue( diff --git a/ui/src/__tests__/pages/domain/[domain]/policy.test.js b/ui/src/__tests__/pages/domain/[domain]/policy.test.js index 7065c86ee40..e06221d2420 100644 --- a/ui/src/__tests__/pages/domain/[domain]/policy.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/policy.test.js @@ -22,6 +22,7 @@ import { renderWithRedux, } from '../../../../tests_utils/ComponentsTestUtils'; import MockApi from '../../../../mock/MockApi'; +import { listUserDomains_response } from '../../../../mock/MockData'; afterEach(() => { MockApi.cleanMockApi(); @@ -38,9 +39,6 @@ describe('PolicyPage', () => { const query = { domain: 'dom', }; - let domains = []; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); const userId = 'pgote'; const domain = 'home.pgote'; const domainDetails = { @@ -74,7 +72,7 @@ describe('PolicyPage', () => { ), listUserDomains: jest.fn().mockReturnValue( new Promise((resolve, reject) => { - resolve(domains); + resolve(listUserDomains_response); }) ), getPolicies: jest.fn().mockReturnValue( diff --git a/ui/src/__tests__/pages/domain/[domain]/policy/[policy]/tags.test.js b/ui/src/__tests__/pages/domain/[domain]/policy/[policy]/tags.test.js index 056312129a5..96f3fcc428d 100644 --- a/ui/src/__tests__/pages/domain/[domain]/policy/[policy]/tags.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/policy/[policy]/tags.test.js @@ -27,15 +27,13 @@ import { singleStorePolicy, } from '../../../../../redux/config/policy.test'; import { storeDomainData } from '../../../../../redux/config/domainData.test'; +import { listUserDomains_response } from '../../../../../../mock/MockData'; describe('Policies Tag Page', () => { afterEach(() => { MockApi.cleanMockApi(); }); it('should render', async () => { - let domains = []; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); const userId = 'test'; const domainDetails = { description: 'test', @@ -73,7 +71,7 @@ describe('Policies Tag Page', () => { .mockReturnValue(Promise.resolve(apiPolicies)), listUserDomains: jest .fn() - .mockReturnValue(Promise.resolve(domains)), + .mockReturnValue(Promise.resolve(listUserDomains_response)), getReviewGroups: jest.fn().mockReturnValue([]), getReviewRoles: jest.fn().mockReturnValue([]), getPageFeatureFlag: jest.fn().mockResolvedValue({}), diff --git a/ui/src/__tests__/pages/domain/[domain]/role.test.js b/ui/src/__tests__/pages/domain/[domain]/role.test.js index 583465d4635..a2befc3d40e 100644 --- a/ui/src/__tests__/pages/domain/[domain]/role.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/role.test.js @@ -22,6 +22,7 @@ import { renderWithRedux, } from '../../../../tests_utils/ComponentsTestUtils'; import MockApi from '../../../../mock/MockApi'; +import { listUserDomains_response } from '../../../../mock/MockData'; afterEach(() => { MockApi.cleanMockApi(); @@ -29,9 +30,6 @@ afterEach(() => { describe('RolePage', () => { it('should render', async () => { - let domains = []; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); let query = { domain: 'dom', }; @@ -70,7 +68,7 @@ describe('RolePage', () => { ), listUserDomains: jest.fn().mockReturnValue( new Promise((resolve, reject) => { - resolve(domains); + resolve(listUserDomains_response); }) ), getReviewGroups: jest.fn().mockReturnValue([]), diff --git a/ui/src/__tests__/pages/domain/[domain]/role/[role]/members.test.js b/ui/src/__tests__/pages/domain/[domain]/role/[role]/members.test.js index 97b898ade10..a2338b5d5fb 100644 --- a/ui/src/__tests__/pages/domain/[domain]/role/[role]/members.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/role/[role]/members.test.js @@ -22,12 +22,10 @@ import { renderWithRedux, } from '../../../../../../tests_utils/ComponentsTestUtils'; import MockApi from '../../../../../../mock/MockApi'; +import { listUserDomains_response } from '../../../../../../mock/MockData'; describe('MemberPage', () => { it('should render', async () => { - let domains = []; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); let query = { domain: 'dom', }; @@ -67,7 +65,7 @@ describe('MemberPage', () => { ...mockRolesApiCalls(), listUserDomains: jest.fn().mockReturnValue( new Promise((resolve, reject) => { - resolve(domains); + resolve(listUserDomains_response); }) ), getDomain: jest.fn().mockReturnValue( diff --git a/ui/src/__tests__/pages/domain/[domain]/role/[role]/policy.test.js b/ui/src/__tests__/pages/domain/[domain]/role/[role]/policy.test.js index fc6891ee649..61f8bb3fae4 100644 --- a/ui/src/__tests__/pages/domain/[domain]/role/[role]/policy.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/role/[role]/policy.test.js @@ -22,15 +22,13 @@ import { renderWithRedux, } from '../../../../../../tests_utils/ComponentsTestUtils'; import MockApi from '../../../../../../mock/MockApi'; +import { listUserDomains_response } from '../../../../../../mock/MockData'; describe('RolePolicyPage', () => { afterEach(() => { MockApi.cleanMockApi(); }); it('should render', async () => { - let domains = []; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); let query = { domain: 'dom', }; @@ -68,7 +66,7 @@ describe('RolePolicyPage', () => { getRole: jest.fn().mockReturnValue(Promise.resolve(roleDetails)), listUserDomains: jest .fn() - .mockReturnValue(Promise.resolve(domains)), + .mockReturnValue(Promise.resolve(listUserDomains_response)), getReviewGroups: jest.fn().mockReturnValue([]), getReviewRoles: jest.fn().mockReturnValue([]), getPageFeatureFlag: jest.fn().mockResolvedValue({}), diff --git a/ui/src/__tests__/pages/domain/[domain]/role/[role]/review.test.js b/ui/src/__tests__/pages/domain/[domain]/role/[role]/review.test.js index afcc71bb763..0809216cb3d 100644 --- a/ui/src/__tests__/pages/domain/[domain]/role/[role]/review.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/role/[role]/review.test.js @@ -22,15 +22,13 @@ import { renderWithRedux, } from '../../../../../../tests_utils/ComponentsTestUtils'; import MockApi from '../../../../../../mock/MockApi'; +import { listUserDomains_response } from '../../../../../../mock/MockData'; describe('ReviewPage', () => { afterEach(() => { MockApi.cleanMockApi(); }); it('should render', async () => { - let domains = []; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); let query = { domain: 'dom', }; @@ -68,7 +66,7 @@ describe('ReviewPage', () => { getRole: jest.fn().mockReturnValue(Promise.resolve(roleDetails)), listUserDomains: jest .fn() - .mockReturnValue(Promise.resolve(domains)), + .mockReturnValue(Promise.resolve(listUserDomains_response)), getReviewGroups: jest.fn().mockReturnValue([]), getReviewRoles: jest.fn().mockReturnValue([]), getPageFeatureFlag: jest.fn().mockResolvedValue({}), diff --git a/ui/src/__tests__/pages/domain/[domain]/role/[role]/tags.test.js b/ui/src/__tests__/pages/domain/[domain]/role/[role]/tags.test.js index 17be6dce558..3c579ce3186 100644 --- a/ui/src/__tests__/pages/domain/[domain]/role/[role]/tags.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/role/[role]/tags.test.js @@ -26,6 +26,7 @@ import { configStoreRoles, singleStoreRole, } from '../../../../../redux/config/role.test'; +import { listUserDomains_response } from '../../../../../../mock/MockData'; describe('Roles Tag Page', () => { afterEach(() => { @@ -35,9 +36,6 @@ describe('Roles Tag Page', () => { const query = { domain: 'dom', }; - let domains = []; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); const userId = 'test'; const domain = 'home.test'; const domainDetails = { @@ -86,7 +84,7 @@ describe('Roles Tag Page', () => { getRoleMembers: jest.fn().mockReturnValue(Promise.resolve([])), listUserDomains: jest .fn() - .mockReturnValue(Promise.resolve(domains)), + .mockReturnValue(Promise.resolve(listUserDomains_response)), getReviewGroups: jest.fn().mockReturnValue([]), getReviewRoles: jest.fn().mockReturnValue([]), getPageFeatureFlag: jest.fn().mockResolvedValue({}), diff --git a/ui/src/__tests__/pages/domain/[domain]/service.test.js b/ui/src/__tests__/pages/domain/[domain]/service.test.js index 8c5d60a1377..b6a9cbfc7cc 100644 --- a/ui/src/__tests__/pages/domain/[domain]/service.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/service.test.js @@ -21,6 +21,7 @@ import { mockAllDomainDataApiCalls, renderWithRedux, } from '../../../../tests_utils/ComponentsTestUtils'; +import { listUserDomains_response } from '../../../../mock/MockData'; afterEach(() => { MockApi.cleanMockApi(); @@ -31,9 +32,6 @@ describe('ServicePage', () => { const query = { domain: 'dom', }; - let domains = []; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); const userId = 'pgote'; const domain = 'home.pgote'; const domainDetails = { @@ -77,7 +75,7 @@ describe('ServicePage', () => { ), listUserDomains: jest.fn().mockReturnValue( new Promise((resolve, reject) => { - resolve(domains); + resolve(listUserDomains_response); }) ), getServices: jest.fn().mockReturnValue( diff --git a/ui/src/__tests__/pages/domain/[domain]/service/[service]/instance/dynamic.test.js b/ui/src/__tests__/pages/domain/[domain]/service/[service]/instance/dynamic.test.js index fc7fae87b0e..400d603530e 100644 --- a/ui/src/__tests__/pages/domain/[domain]/service/[service]/instance/dynamic.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/service/[service]/instance/dynamic.test.js @@ -23,6 +23,7 @@ import { renderWithRedux, } from '../../../../../../../tests_utils/ComponentsTestUtils'; import DynamicInstancePage from '../../../../../../../pages/domain/[domain]/service/[service]/instance/dynamic'; +import { listUserDomains_response } from '../../../../../../../mock/MockData'; const testInstancedetails = { workLoadData: [ @@ -48,10 +49,6 @@ const testInstancedetails = { describe('DynamicInstancePage', () => { afterEach(() => MockApi.cleanMockApi()); it('should render', async () => { - let domains = []; - let instanceDetails = testInstancedetails; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); let query = { domain: 'dom', service: 'serv', @@ -98,7 +95,7 @@ describe('DynamicInstancePage', () => { .mockReturnValue(Promise.resolve([])), listUserDomains: jest .fn() - .mockReturnValue(Promise.resolve(domains)), + .mockReturnValue(Promise.resolve(listUserDomains_response)), getReviewGroups: jest.fn().mockReturnValue([]), getReviewRoles: jest.fn().mockReturnValue([]), getPageFeatureFlag: jest.fn().mockResolvedValue({}), diff --git a/ui/src/__tests__/pages/domain/[domain]/service/[service]/instance/static.test.js b/ui/src/__tests__/pages/domain/[domain]/service/[service]/instance/static.test.js index a1e070cdd10..dbdd5e9fe6f 100644 --- a/ui/src/__tests__/pages/domain/[domain]/service/[service]/instance/static.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/service/[service]/instance/static.test.js @@ -23,6 +23,7 @@ import { renderWithRedux, } from '../../../../../../../tests_utils/ComponentsTestUtils'; import MockApi from '../../../../../../../mock/MockApi'; +import { listUserDomains_response } from '../../../../../../../mock/MockData'; const testInstancedetails = { workLoadData: [ @@ -47,10 +48,6 @@ const testInstancedetails = { describe('StaticInstancePage', () => { it('should render', async () => { - let domains = []; - let instanceDetails = testInstancedetails; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); let query = { domain: 'dom', service: 'serv', @@ -99,7 +96,7 @@ describe('StaticInstancePage', () => { .mockReturnValue(Promise.resolve([])), listUserDomains: jest .fn() - .mockReturnValue(Promise.resolve(domains)), + .mockReturnValue(Promise.resolve(listUserDomains_response)), getReviewGroups: jest.fn().mockReturnValue([]), getReviewRoles: jest.fn().mockReturnValue([]), getPageFeatureFlag: jest.fn().mockResolvedValue({}), diff --git a/ui/src/__tests__/pages/domain/[domain]/service/[service]/microsegmentation.test.js b/ui/src/__tests__/pages/domain/[domain]/service/[service]/microsegmentation.test.js index bb1934ae663..2576e20f4db 100644 --- a/ui/src/__tests__/pages/domain/[domain]/service/[service]/microsegmentation.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/service/[service]/microsegmentation.test.js @@ -26,15 +26,13 @@ import { apiAssertionConditions, modified, } from '../../../../../config/config.test'; +import { listUserDomains_response } from '../../../../../../mock/MockData'; describe('Service Microsegmentation Page', () => { afterEach(() => { MockApi.cleanMockApi(); }); it('should render', async () => { - let domains = []; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); const userId = 'test'; const domainDetails = { description: 'test', @@ -168,7 +166,7 @@ describe('Service Microsegmentation Page', () => { ), listUserDomains: jest .fn() - .mockReturnValue(Promise.resolve(domains)), + .mockReturnValue(Promise.resolve(listUserDomains_response)), getPolicies: jest.fn().mockReturnValue(Promise.resolve(policies)), getServices: jest .fn() diff --git a/ui/src/__tests__/pages/domain/[domain]/service/[service]/tags.test.js b/ui/src/__tests__/pages/domain/[domain]/service/[service]/tags.test.js index 93de6a5361f..bb85eceabcf 100644 --- a/ui/src/__tests__/pages/domain/[domain]/service/[service]/tags.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/service/[service]/tags.test.js @@ -25,15 +25,13 @@ import { singleStoreService, } from '../../../../../redux/config/service.test'; import ServiceTagsPage from '../../../../../../pages/domain/[domain]/service/[service]/tags'; +import { listUserDomains_response } from '../../../../../../mock/MockData'; describe('Service Tag Page', () => { afterEach(() => { MockApi.cleanMockApi(); }); it('should render', async () => { - let domains = []; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); const userId = 'test'; const domainDetails = { description: 'test', @@ -70,7 +68,7 @@ describe('Service Tag Page', () => { .mockReturnValue(Promise.resolve(apiServices)), listUserDomains: jest .fn() - .mockReturnValue(Promise.resolve(domains)), + .mockReturnValue(Promise.resolve(listUserDomains_response)), getReviewGroups: jest.fn().mockReturnValue([]), getReviewRoles: jest.fn().mockReturnValue([]), getPageFeatureFlag: jest.fn().mockResolvedValue({}), diff --git a/ui/src/__tests__/pages/domain/[domain]/tags.test.js b/ui/src/__tests__/pages/domain/[domain]/tags.test.js index b4dee799ad5..7f9e6d39e13 100644 --- a/ui/src/__tests__/pages/domain/[domain]/tags.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/tags.test.js @@ -21,6 +21,7 @@ import { } from '../../../../tests_utils/ComponentsTestUtils'; import MockApi from '../../../../mock/MockApi'; import TagsPage from '../../../../pages/domain/[domain]/tags'; +import { listUserDomains_response } from '../../../../mock/MockData'; afterEach(() => { MockApi.cleanMockApi(); @@ -31,9 +32,6 @@ describe('Tag Page', () => { const query = { domain: 'dom', }; - let domains = []; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); const userId = 'test'; const domain = 'home.test'; const domainDetails = { @@ -66,7 +64,7 @@ describe('Tag Page', () => { ), listUserDomains: jest.fn().mockReturnValue( new Promise((resolve, reject) => { - resolve(domains); + resolve(listUserDomains_response); }) ), getReviewGroups: jest.fn().mockReturnValue([]), diff --git a/ui/src/__tests__/pages/domain/[domain]/template.test.js b/ui/src/__tests__/pages/domain/[domain]/template.test.js index 2b34c4272d6..3fc2b731426 100644 --- a/ui/src/__tests__/pages/domain/[domain]/template.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/template.test.js @@ -21,6 +21,7 @@ import { renderWithRedux, } from '../../../../tests_utils/ComponentsTestUtils'; import MockApi from '../../../../mock/MockApi'; +import { listUserDomains_response } from '../../../../mock/MockData'; afterEach(() => { MockApi.cleanMockApi(); @@ -31,9 +32,6 @@ describe('Template Page', () => { const query = { domain: 'dom', }; - let domains = []; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); const userId = 'test'; const domain = 'home.test'; const domainDetails = { @@ -66,7 +64,7 @@ describe('Template Page', () => { ), listUserDomains: jest.fn().mockReturnValue( new Promise((resolve, reject) => { - resolve(domains); + resolve(listUserDomains_response); }) ), getReviewGroups: jest.fn().mockReturnValue([]), diff --git a/ui/src/__tests__/pages/domain/[domain]/visibility.test.js b/ui/src/__tests__/pages/domain/[domain]/visibility.test.js index 3382e3ae5e3..6233bdecc1c 100644 --- a/ui/src/__tests__/pages/domain/[domain]/visibility.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/visibility.test.js @@ -21,6 +21,7 @@ import { } from '../../../../tests_utils/ComponentsTestUtils'; import MockApi from '../../../../mock/MockApi'; import { waitFor } from '@testing-library/react'; +import { listUserDomains_response } from '../../../../mock/MockData'; afterEach(() => { MockApi.cleanMockApi(); @@ -28,10 +29,7 @@ afterEach(() => { describe('VisibilityPage', () => { it('should render', async () => { - let domains = []; const domainName = 'dom'; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); let query = { domain: domainName, }; @@ -70,7 +68,7 @@ describe('VisibilityPage', () => { ), listUserDomains: jest.fn().mockReturnValue( new Promise((resolve, reject) => { - resolve(domains); + resolve(listUserDomains_response); }) ), getReviewGroups: jest.fn().mockReturnValue([]), diff --git a/ui/src/__tests__/pages/domain/create.test.js b/ui/src/__tests__/pages/domain/create.test.js index 9aa77691ed1..10a1a7677cd 100644 --- a/ui/src/__tests__/pages/domain/create.test.js +++ b/ui/src/__tests__/pages/domain/create.test.js @@ -18,6 +18,7 @@ import CreateDomainPage from '../../../pages/domain/create'; import { renderWithRedux } from '../../../tests_utils/ComponentsTestUtils'; import MockApi from '../../../mock/MockApi'; import { waitFor } from '@testing-library/react'; +import { listUserDomains_response } from '../../../mock/MockData'; afterEach(() => { MockApi.cleanMockApi(); @@ -25,9 +26,6 @@ afterEach(() => { describe('CreateDomainPage', () => { it('should render', async () => { - let domains = []; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); let query = { domain: 'dom', }; @@ -47,7 +45,7 @@ describe('CreateDomainPage', () => { const mockApi = { listUserDomains: jest.fn().mockReturnValue( new Promise((resolve, reject) => { - resolve(domains); + resolve(listUserDomains_response); }) ), getPendingDomainMembersList: jest.fn().mockReturnValue( diff --git a/ui/src/__tests__/pages/domain/manage.test.js b/ui/src/__tests__/pages/domain/manage.test.js index 7e0aaf37763..444918c8d5a 100644 --- a/ui/src/__tests__/pages/domain/manage.test.js +++ b/ui/src/__tests__/pages/domain/manage.test.js @@ -18,6 +18,7 @@ import ManageDomainsPage from '../../../pages/domain/manage'; import { renderWithRedux } from '../../../tests_utils/ComponentsTestUtils'; import MockApi from '../../../mock/MockApi'; import { getByText, waitFor } from '@testing-library/react'; +import { listUserDomains_response } from '../../../mock/MockData'; afterEach(() => { MockApi.cleanMockApi(); @@ -25,9 +26,6 @@ afterEach(() => { describe('PageManageDomains', () => { it('should render', async () => { - let domains = []; - domains.push({ name: 'athens' }); - domains.push({ name: 'athens.ci' }); const userId = 'pgote'; const manageDomains = [ { @@ -102,7 +100,7 @@ describe('PageManageDomains', () => { const mockApi = { listUserDomains: jest.fn().mockReturnValue( new Promise((resolve, reject) => { - resolve(domains); + resolve(listUserDomains_response); }) ), getMeta: jest.fn().mockReturnValue( diff --git a/ui/src/__tests__/redux/reducers/domains.test.js b/ui/src/__tests__/redux/reducers/domains.test.js index 632e2ea27bf..c669c555809 100644 --- a/ui/src/__tests__/redux/reducers/domains.test.js +++ b/ui/src/__tests__/redux/reducers/domains.test.js @@ -49,6 +49,7 @@ import { configHeaderDetails, } from '../config/domains.test'; import { storeDomainData } from '../config/domainData.test'; +import { listUserDomains_responseTransformed } from '../../../mock/MockData'; const userDomains = [ { name: 'userDomain1', adminDomain: true }, @@ -60,14 +61,14 @@ describe('Domains Reducer', () => { const action = { type: LOAD_USER_DOMAINS_LIST, payload: { - domainsList: userDomains, - }, + domainsList: listUserDomains_responseTransformed + } }; const expectedState = { - domainsList: userDomains, + domainsList: listUserDomains_responseTransformed, }; const newState = domains(initialState, action); - expect(_.isEqual(newState, expectedState)).toBeTruthy(); + expect(_.isEqual(_.sortBy(newState), _.sortBy(expectedState))).toBeTruthy(); }); it('should load all Business Services', () => { const businessServicesAll = [ diff --git a/ui/src/__tests__/redux/thunk/domains.test.js b/ui/src/__tests__/redux/thunk/domains.test.js index 36da19b0fbb..59d48c6cbdd 100644 --- a/ui/src/__tests__/redux/thunk/domains.test.js +++ b/ui/src/__tests__/redux/thunk/domains.test.js @@ -49,11 +49,8 @@ import { } from '../../config/config.test'; import { getFullName } from '../../../redux/utils'; import { subDomainDelimiter } from '../../../redux/config'; +import { listUserDomains_response, listUserDomains_responseTransformed } from '../../../mock/MockData'; -const userDomains = [ - { name: 'userDomain1', adminDomain: true }, - { name: 'UserDomain2', adminDomain: false }, -]; const domainsSelectors = require('../../../redux/selectors/domains'); describe('test getUserDomainsList thunk', () => { @@ -64,7 +61,7 @@ describe('test getUserDomainsList thunk', () => { const fakeDispatch = sinon.spy(); const getState = () => { return { - domains: { domainsList: userDomains }, + domains: { domainsList: listUserDomains_responseTransformed }, }; }; @@ -84,7 +81,7 @@ describe('test getUserDomainsList thunk', () => { MockApi.setMockApi({ listUserDomains: jest .fn() - .mockReturnValue(Promise.resolve(userDomains)), + .mockReturnValue(Promise.resolve(listUserDomains_response)), }); await getUserDomainsList()(fakeDispatch, getState); @@ -98,7 +95,7 @@ describe('test getUserDomainsList thunk', () => { expect( _.isEqual( fakeDispatch.getCall(1).args[0], - loadUserDomainList(userDomains) + loadUserDomainList(listUserDomains_responseTransformed) ) ).toBeTruthy(); expect( diff --git a/ui/src/__tests__/server/handlers/api.test.js b/ui/src/__tests__/server/handlers/api.test.js index 0ab0f06bbe0..2d523aebfa2 100644 --- a/ui/src/__tests__/server/handlers/api.test.js +++ b/ui/src/__tests__/server/handlers/api.test.js @@ -43,6 +43,7 @@ const secrets = {}; const expressApp = require('express')(); const request = require('supertest'); const bodyParser = require('body-parser'); +const { listUserDomains_response, getPrincipalRoles_response } = require('../../../mock/MockData'); describe('Fetchr Server API Test', () => { describe('success tests', () => { @@ -83,6 +84,21 @@ describe('Fetchr Server API Test', () => { params.forcefail ? callback({ status: 404 }, null) : callback(undefined, { success: 'true' }), + getPrincipalRoles: (params, callback) => { + if (params.principal && + params.principal != + `${config.userDomain}.testuser` + ) { + // If the specified member is not included in any role in all domains, an empty array is responded. + callback(undefined, { + memberRoles: [], + }); + return; + } + params.forcefail + ? callback({ status: 404 }, null) + : callback(undefined, {...getPrincipalRoles_response}); + }, putDomainTemplate: (params, callback) => params.forcefail ? callback({ status: 404 }, null) @@ -534,12 +550,9 @@ describe('Fetchr Server API Test', () => { }); it('domainList test success', async () => { await request(expressApp) - .get('/api/v1/domain-list') + .get('/api/v1/domain-role-member') .then((res) => { - expect(res.body).toEqual([ - { adminDomain: true, name: 'dom1' }, - { adminDomain: true, name: 'domabc1' }, - ]); + expect(res.body).toEqual(listUserDomains_response); }); }); it('getForm test success', async () => { diff --git a/ui/src/api.js b/ui/src/api.js index cb0ea1481d3..42c3afda5ab 100644 --- a/ui/src/api.js +++ b/ui/src/api.js @@ -36,11 +36,11 @@ const Api = (req) => { return undefined; }, - listUserDomains(roleName) { + listUserDomains() { return new Promise((resolve, reject) => { fetchr - .read('domain-list') - .params({ roleName }) + .read('domain-role-member') + .params({ expand: true }) .end((err, data) => { if (err) { reject(err); diff --git a/ui/src/mock/MockData.js b/ui/src/mock/MockData.js new file mode 100644 index 00000000000..f54a273b365 --- /dev/null +++ b/ui/src/mock/MockData.js @@ -0,0 +1,33 @@ +/* + * Copyright The Athenz Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// to store common data used in tests + +export const getPrincipalRoles_response = { + memberRoles: [ + { domainName: 'athens', roleName: 'somerole' }, + { domainName: 'athens.ci', roleName: 'somerole' }, + ] +} +export const listUserDomains_response = { + ...getPrincipalRoles_response, + prefix: ['athens', 'athens.ci'], +}; + +export const listUserDomains_responseTransformed = [ + { name: 'athens', adminDomain: false }, + { name: 'athens.ci', adminDomain: false }, +]; diff --git a/ui/src/pages/domain/[domain]/group/[group]/roles.js b/ui/src/pages/domain/[domain]/group/[group]/roles.js index 0b18c172f59..ea48a3a073e 100644 --- a/ui/src/pages/domain/[domain]/group/[group]/roles.js +++ b/ui/src/pages/domain/[domain]/group/[group]/roles.js @@ -29,7 +29,6 @@ import GroupRoleTable from '../../../../../components/group/GroupRoleTable'; import SearchInput from '../../../../../components/denali/SearchInput'; import { getDomainData } from '../../../../../redux/thunks/domain'; import { - getDomainRoleMembers, getGroup, } from '../../../../../redux/thunks/groups'; import { connect } from 'react-redux'; diff --git a/ui/src/redux/thunks/domains.js b/ui/src/redux/thunks/domains.js index 3c16204fe94..8924f62600f 100644 --- a/ui/src/redux/thunks/domains.js +++ b/ui/src/redux/thunks/domains.js @@ -51,7 +51,8 @@ export const getUserDomainsList = () => async (dispatch, getState) => { try { if (!getState().domains.domainsList) { dispatch(loadingInProcess('getUserDomainsList')); - const domainsList = await API().listUserDomains(); + const domainsData = await API().listUserDomains(); + const domainsList = transformDomainListResult(domainsData); dispatch(loadUserDomainList(domainsList)); dispatch(loadingSuccess('getUserDomainsList')); } else { @@ -266,3 +267,48 @@ export const processPendingMembers = throw err; } }; + + +const transformDomainListResult = (domainsData) => { + let domainsToReturn = []; + + // 'prefix' is a list of unique domain names for given principal + if (!domainsData || !domainsData.memberRoles || !domainsData['prefix']) { + return domainsToReturn; + } + + let adminDomains = new Set(); + let nonAdminDomains = domainsData['prefix'].slice(); // list of all unique domain names + + // processing non-admin domains separately because user can be an admin of same domain only once + // but can be non-admin member of same domain via multiple roles/groups + domainsData.memberRoles.forEach(role => { + if (role.roleName === 'admin') { + // create admin domain object + adminDomains.add({ + name: role.domainName, + adminDomain: true + }); + // remove admin domain from list of non admin domains + const adminDomainIndex = nonAdminDomains.indexOf(role.domainName); + nonAdminDomains.splice(adminDomainIndex, 1); + } + }); + + // add admin domains + domainsToReturn.push(...adminDomains); + + // create and add non admin domains + nonAdminDomains.forEach(domain => { + domainsToReturn.push({ + name: domain, + adminDomain: false + }) + }) + + // sorting domains alphabetically + domainsToReturn.sort((a, b) => a.name.localeCompare(b.name)); + + return domainsToReturn; +}; + From 3b43e5e7a8cb29d3248755c2f3e9e109be8d2a31 Mon Sep 17 00:00:00 2001 From: aporss Date: Tue, 5 Nov 2024 18:37:59 +0000 Subject: [PATCH 2/2] prettier formatting changes Signed-off-by: aporss --- .../components/utils/ReviewUtils.test.js | 53 +++++++---- .../[service]/instance/dynamic.test.js | 4 +- .../service/[service]/instance/static.test.js | 2 +- .../__tests__/redux/reducers/domains.test.js | 8 +- ui/src/__tests__/redux/thunk/domains.test.js | 5 +- ui/src/__tests__/server/handlers/api.test.js | 14 ++- ui/src/__tests__/spec/tests/domain.spec.js | 90 +++++++++++++------ ui/src/__tests__/spec/tests/groups.spec.js | 25 ++++-- ui/src/api.js | 2 +- ui/src/mock/MockData.js | 6 +- ui/src/pages/workflow/domain.js | 5 +- ui/src/redux/thunks/domains.js | 14 ++- 12 files changed, 152 insertions(+), 76 deletions(-) diff --git a/ui/src/__tests__/components/utils/ReviewUtils.test.js b/ui/src/__tests__/components/utils/ReviewUtils.test.js index 3eb0b752ad1..bc772a0520e 100644 --- a/ui/src/__tests__/components/utils/ReviewUtils.test.js +++ b/ui/src/__tests__/components/utils/ReviewUtils.test.js @@ -21,49 +21,65 @@ import { } from '../../../components/utils/ReviewUtils'; describe('ReviewUtils', (object, method) => { - afterAll(() => { jest.clearAllMocks(); }); - it('getSmallestExpiryOrReview check memberExpiryDays value is picked up', async () => { - const role = { memberExpiryDays: 5, lastReviewedDate: '2024-07-24T10:58:07.533Z' }; + const role = { + memberExpiryDays: 5, + lastReviewedDate: '2024-07-24T10:58:07.533Z', + }; let actualDays = getSmallestExpiryOrReview(role); expect(_.isEqual(role.memberExpiryDays, actualDays)).toBeTruthy(); }); it('getSmallestExpiryOrReview check serviceExpiryDays value is picked up', async () => { - const role = { serviceExpiryDays: 9, lastReviewedDate: '2024-07-24T10:58:07.533Z' }; + const role = { + serviceExpiryDays: 9, + lastReviewedDate: '2024-07-24T10:58:07.533Z', + }; let actualDays = getSmallestExpiryOrReview(role); expect(_.isEqual(role.serviceExpiryDays, actualDays)).toBeTruthy(); }); it('getSmallestExpiryOrReview check memberReviewDays value is picked up', async () => { - const role = { memberReviewDays: 6, lastReviewedDate: '2024-07-24T10:58:07.533Z' }; + const role = { + memberReviewDays: 6, + lastReviewedDate: '2024-07-24T10:58:07.533Z', + }; let actualDays = getSmallestExpiryOrReview(role); expect(_.isEqual(role.memberReviewDays, actualDays)).toBeTruthy(); }); it('getSmallestExpiryOrReview check serviceReviewDays value is picked up', async () => { - const role = { serviceReviewDays: 10, lastReviewedDate: '2024-07-24T10:58:07.533Z' }; + const role = { + serviceReviewDays: 10, + lastReviewedDate: '2024-07-24T10:58:07.533Z', + }; let actualDays = getSmallestExpiryOrReview(role); expect(_.isEqual(role.serviceReviewDays, actualDays)).toBeTruthy(); }); it('getSmallestExpiryOrReview check groupReviewDays value is picked up', async () => { - const role = { groupReviewDays: 8, lastReviewedDate: '2024-07-24T10:58:07.533Z' }; + const role = { + groupReviewDays: 8, + lastReviewedDate: '2024-07-24T10:58:07.533Z', + }; let actualDays = getSmallestExpiryOrReview(role); expect(_.isEqual(role.groupReviewDays, actualDays)).toBeTruthy(); }); it('getSmallestExpiryOrReview check groupExpiryDays value is picked up', async () => { - const role = { groupExpiryDays: 7, lastReviewedDate: '2024-07-24T10:58:07.533Z' }; + const role = { + groupExpiryDays: 7, + lastReviewedDate: '2024-07-24T10:58:07.533Z', + }; let actualDays = getSmallestExpiryOrReview(role); expect(_.isEqual(role.groupExpiryDays, actualDays)).toBeTruthy(); @@ -77,47 +93,48 @@ describe('ReviewUtils', (object, method) => { serviceReviewDays: 10, groupReviewDays: 8, groupExpiryDays: 7, - lastReviewedDate: '2024-07-24T10:58:07.533Z' + lastReviewedDate: '2024-07-24T10:58:07.533Z', }; let actualDays = getSmallestExpiryOrReview(role); expect(_.isEqual(role.memberReviewDays, actualDays)).toBeTruthy(); }); - it("getSmallestExpiryOrReview when no expiry or review days assigned to the role, return 0", async () => { + it('getSmallestExpiryOrReview when no expiry or review days assigned to the role, return 0', async () => { const role = { - lastReviewedDate: '2024-07-24T10:58:07.533Z' + lastReviewedDate: '2024-07-24T10:58:07.533Z', }; let actualDays = getSmallestExpiryOrReview(role); expect(_.isEqual(0, actualDays)).toBeTruthy(); }); - it("isReviewRequired when no expiry or review days assigned to the role, return false", async () => { + it('isReviewRequired when no expiry or review days assigned to the role, return false', async () => { const role = {}; let reviewRequired = isReviewRequired(role); expect(_.isEqual(false, reviewRequired)).toBeTruthy(); }); - it("isReviewRequired when lastReviewDate is more than 80% of memberExpiryDate ago - return true", async () => { + it('isReviewRequired when lastReviewDate is more than 80% of memberExpiryDate ago - return true', async () => { const role = { lastReviewedDate: '2024-07-01T11:59:59.000Z', - memberExpiryDays: '10' + memberExpiryDays: '10', }; // mock current date - jest.spyOn(moment.prototype, 'utc') - .mockReturnValue(moment('2024-07-09T12:00:00.000Z').utc()); + jest.spyOn(moment.prototype, 'utc').mockReturnValue( + moment('2024-07-09T12:00:00.000Z').utc() + ); let reviewRequired = isReviewRequired(role); expect(_.isEqual(true, reviewRequired)).toBeTruthy(); }); - it("isReviewRequired when lastReviewDate is less than 80% of memberExpiryDate ago - return false", async () => { + it('isReviewRequired when lastReviewDate is less than 80% of memberExpiryDate ago - return false', async () => { const role = { lastReviewedDate: '2024-07-01T12:00:01.000Z', - memberExpiryDays: '10' + memberExpiryDays: '10', }; // mock current date // jest.spyOn(moment.prototype, 'utc') diff --git a/ui/src/__tests__/pages/domain/[domain]/service/[service]/instance/dynamic.test.js b/ui/src/__tests__/pages/domain/[domain]/service/[service]/instance/dynamic.test.js index 400d603530e..c8bbe66e594 100644 --- a/ui/src/__tests__/pages/domain/[domain]/service/[service]/instance/dynamic.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/service/[service]/instance/dynamic.test.js @@ -73,12 +73,12 @@ describe('DynamicInstancePage', () => { }, }; let serviceHeaderDetails = { - dynamic : { + dynamic: { description: 'Here you can see instances which are running with this service identity', url: '', target: '_blank', - } + }, }; let services = { 'dom.serv': { diff --git a/ui/src/__tests__/pages/domain/[domain]/service/[service]/instance/static.test.js b/ui/src/__tests__/pages/domain/[domain]/service/[service]/instance/static.test.js index dbdd5e9fe6f..a8656765742 100644 --- a/ui/src/__tests__/pages/domain/[domain]/service/[service]/instance/static.test.js +++ b/ui/src/__tests__/pages/domain/[domain]/service/[service]/instance/static.test.js @@ -78,7 +78,7 @@ describe('StaticInstancePage', () => { 'Here you can add / see instances which can not obtain Athenz identity because of limitations, but would be associated with your service.', url: '', target: '_blank', - } + }, }; let services = { 'dom.serv': { diff --git a/ui/src/__tests__/redux/reducers/domains.test.js b/ui/src/__tests__/redux/reducers/domains.test.js index c669c555809..2b6f7197680 100644 --- a/ui/src/__tests__/redux/reducers/domains.test.js +++ b/ui/src/__tests__/redux/reducers/domains.test.js @@ -61,14 +61,16 @@ describe('Domains Reducer', () => { const action = { type: LOAD_USER_DOMAINS_LIST, payload: { - domainsList: listUserDomains_responseTransformed - } + domainsList: listUserDomains_responseTransformed, + }, }; const expectedState = { domainsList: listUserDomains_responseTransformed, }; const newState = domains(initialState, action); - expect(_.isEqual(_.sortBy(newState), _.sortBy(expectedState))).toBeTruthy(); + expect( + _.isEqual(_.sortBy(newState), _.sortBy(expectedState)) + ).toBeTruthy(); }); it('should load all Business Services', () => { const businessServicesAll = [ diff --git a/ui/src/__tests__/redux/thunk/domains.test.js b/ui/src/__tests__/redux/thunk/domains.test.js index 59d48c6cbdd..8870fa8e389 100644 --- a/ui/src/__tests__/redux/thunk/domains.test.js +++ b/ui/src/__tests__/redux/thunk/domains.test.js @@ -49,7 +49,10 @@ import { } from '../../config/config.test'; import { getFullName } from '../../../redux/utils'; import { subDomainDelimiter } from '../../../redux/config'; -import { listUserDomains_response, listUserDomains_responseTransformed } from '../../../mock/MockData'; +import { + listUserDomains_response, + listUserDomains_responseTransformed, +} from '../../../mock/MockData'; const domainsSelectors = require('../../../redux/selectors/domains'); diff --git a/ui/src/__tests__/server/handlers/api.test.js b/ui/src/__tests__/server/handlers/api.test.js index 2d523aebfa2..166af18e1c3 100644 --- a/ui/src/__tests__/server/handlers/api.test.js +++ b/ui/src/__tests__/server/handlers/api.test.js @@ -43,7 +43,10 @@ const secrets = {}; const expressApp = require('express')(); const request = require('supertest'); const bodyParser = require('body-parser'); -const { listUserDomains_response, getPrincipalRoles_response } = require('../../../mock/MockData'); +const { + listUserDomains_response, + getPrincipalRoles_response, +} = require('../../../mock/MockData'); describe('Fetchr Server API Test', () => { describe('success tests', () => { @@ -85,9 +88,10 @@ describe('Fetchr Server API Test', () => { ? callback({ status: 404 }, null) : callback(undefined, { success: 'true' }), getPrincipalRoles: (params, callback) => { - if (params.principal && + if ( + params.principal && params.principal != - `${config.userDomain}.testuser` + `${config.userDomain}.testuser` ) { // If the specified member is not included in any role in all domains, an empty array is responded. callback(undefined, { @@ -97,7 +101,9 @@ describe('Fetchr Server API Test', () => { } params.forcefail ? callback({ status: 404 }, null) - : callback(undefined, {...getPrincipalRoles_response}); + : callback(undefined, { + ...getPrincipalRoles_response, + }); }, putDomainTemplate: (params, callback) => params.forcefail diff --git a/ui/src/__tests__/spec/tests/domain.spec.js b/ui/src/__tests__/spec/tests/domain.spec.js index ac34f85c883..7f48f2ec500 100644 --- a/ui/src/__tests__/spec/tests/domain.spec.js +++ b/ui/src/__tests__/spec/tests/domain.spec.js @@ -57,13 +57,19 @@ describe('Domain', () => { await expect(browser).toHaveUrlContaining('athenz'); // expand domain details - let expand = await $(`.//*[local-name()="svg" and @data-wdio="domain-details-expand-icon"]`); + let expand = await $( + `.//*[local-name()="svg" and @data-wdio="domain-details-expand-icon"]` + ); await browser.waitUntil(async () => await expand.isClickable()); await expand.click(); // click add business service - let addBusinessService = await $('a[data-testid="add-business-service"]'); - await browser.waitUntil(async () => await addBusinessService.isClickable()); + let addBusinessService = await $( + 'a[data-testid="add-business-service"]' + ); + await browser.waitUntil( + async () => await addBusinessService.isClickable() + ); await addBusinessService.click(); await browser.pause(2000); // wait to make sure dropdown options are loaded @@ -88,22 +94,27 @@ describe('Domain', () => { // verify error message let errorMessage = await $('div[data-testid="error-message"]'); - expect(await errorMessage.getText()).toBe('Business Service must be selected in the dropdown or clear input before submitting'); + expect(await errorMessage.getText()).toBe( + 'Business Service must be selected in the dropdown or clear input before submitting' + ); // unclick checkbox to allow selection of business services not associated with current account let checkbox = await $('input[id="checkbox-show-all-bservices"]'); - await browser.execute(function(checkboxElem) { + await browser.execute(function (checkboxElem) { checkboxElem.click(); }, checkbox); - // type valid input and select item in dropdown - let clearInput = await $(`.//*[local-name()="svg" and @data-wdio="clear-input"]`); + let clearInput = await $( + `.//*[local-name()="svg" and @data-wdio="clear-input"]` + ); await clearInput.click(); // make dropdown visible await bsInput.click(); await bsInput.addValue('PolicyEnforcementService.GLB'); - let dropdownOption = await $('//div[contains(text(), "PolicyEnforcementService.GLB")]'); + let dropdownOption = await $( + '//div[contains(text(), "PolicyEnforcementService.GLB")]' + ); await dropdownOption.click(); // verify input contains pes service @@ -119,14 +130,20 @@ describe('Domain', () => { // business service can be seen added to domain addBusinessService = await $('a[data-testid="add-business-service"]'); - await expect(addBusinessService).toHaveTextContaining('PolicyEnforcementService.GLB'); + await expect(addBusinessService).toHaveTextContaining( + 'PolicyEnforcementService.GLB' + ); // click add business service - await browser.waitUntil(async () => await addBusinessService.isClickable()); + await browser.waitUntil( + async () => await addBusinessService.isClickable() + ); await addBusinessService.click(); // clear current input - clearInput = await $(`.//*[local-name()="svg" and @data-wdio="clear-input"]`); + clearInput = await $( + `.//*[local-name()="svg" and @data-wdio="clear-input"]` + ); await browser.waitUntil(async () => await clearInput.isClickable()); await clearInput.click(); @@ -135,7 +152,9 @@ describe('Domain', () => { await submitButton.click(); // business service for the domain should be empty - await browser.waitUntil(async () => await addBusinessService.isClickable()); + await browser.waitUntil( + async () => await addBusinessService.isClickable() + ); expect(addBusinessService).toHaveTextContaining('add'); }); @@ -147,8 +166,12 @@ describe('Domain', () => { await expect(browser).toHaveUrlContaining('athenz'); // click add business service - let addBusinessService = await $('a[data-testid="business-service-athenz.dev.functional-test"]'); - await browser.waitUntil(async () => await addBusinessService.isClickable()); + let addBusinessService = await $( + 'a[data-testid="business-service-athenz.dev.functional-test"]' + ); + await browser.waitUntil( + async () => await addBusinessService.isClickable() + ); await addBusinessService.click(); await browser.pause(4000); // wait to make sure dropdown options are loaded @@ -173,17 +196,20 @@ describe('Domain', () => { // verify error message let errorMessage = await $('div[data-testid="error-message"]'); - expect(await errorMessage.getText()).toBe('Business Service must be selected in the dropdown'); + expect(await errorMessage.getText()).toBe( + 'Business Service must be selected in the dropdown' + ); - let clearInput = await $(`.//*[local-name()="svg" and @data-wdio="clear-input"]`); + let clearInput = await $( + `.//*[local-name()="svg" and @data-wdio="clear-input"]` + ); await clearInput.click(); let checkbox = await $('input[id="checkbox-show-all-bservices"]'); - await browser.execute(function(checkboxElem) { + await browser.execute(function (checkboxElem) { checkboxElem.click(); }, checkbox); - // make dropdown visible await bsInput.click(); // type valid input and select item in dropdown @@ -203,15 +229,23 @@ describe('Domain', () => { await submitButton.click(); // business service can be seen added to domain - addBusinessService = await $('a[data-testid="business-service-athenz.dev.functional-test"]'); - await expect(addBusinessService).toHaveTextContaining('PolicyEnforcementService.GLB'); + addBusinessService = await $( + 'a[data-testid="business-service-athenz.dev.functional-test"]' + ); + await expect(addBusinessService).toHaveTextContaining( + 'PolicyEnforcementService.GLB' + ); // click add business service - await browser.waitUntil(async () => await addBusinessService.isClickable()); + await browser.waitUntil( + async () => await addBusinessService.isClickable() + ); await addBusinessService.click(); // clear current input - clearInput = await $(`.//*[local-name()="svg" and @data-wdio="clear-input"]`); + clearInput = await $( + `.//*[local-name()="svg" and @data-wdio="clear-input"]` + ); await browser.waitUntil(async () => await clearInput.isClickable()); await clearInput.click(); @@ -220,7 +254,9 @@ describe('Domain', () => { await submitButton.click(); // business service for the domain should be empty - await browser.waitUntil(async () => await addBusinessService.isClickable()); + await browser.waitUntil( + async () => await addBusinessService.isClickable() + ); expect(addBusinessService).toHaveTextContaining('add'); }); @@ -247,7 +283,9 @@ describe('Domain', () => { let fontWeight = await input.getCSSProperty('font-weight').value; expect(fontWeight).toBeUndefined(); - let clearInput = await $(`.//*[local-name()="svg" and @data-wdio="clear-input"]`); + let clearInput = await $( + `.//*[local-name()="svg" and @data-wdio="clear-input"]` + ); await clearInput.click(); // type valid input and select item in dropdown @@ -286,7 +324,9 @@ describe('Domain', () => { let fontWeight = await input.getCSSProperty('font-weight').value; expect(fontWeight).toBeUndefined(); - let clearInput = await $(`.//*[local-name()="svg" and @data-wdio="clear-input"]`); + let clearInput = await $( + `.//*[local-name()="svg" and @data-wdio="clear-input"]` + ); await clearInput.click(); // type valid input and select item in dropdown diff --git a/ui/src/__tests__/spec/tests/groups.spec.js b/ui/src/__tests__/spec/tests/groups.spec.js index 0f70ddb54d4..917300a56e0 100644 --- a/ui/src/__tests__/spec/tests/groups.spec.js +++ b/ui/src/__tests__/spec/tests/groups.spec.js @@ -14,8 +14,6 @@ * limitations under the License. */ - - describe('group screen tests', () => { it('group history should be visible when navigating to it and after page refresh', async () => { // open browser @@ -48,7 +46,9 @@ describe('group screen tests', () => { // Verify history entry of added group member is present // open history - let historySvg = await $('.//*[local-name()="svg" and @id="group-history-icon-history-test-group"]'); + let historySvg = await $( + './/*[local-name()="svg" and @id="group-history-icon-history-test-group"]' + ); await historySvg.click(); // find row with 'ADD' let addTd = await $('td=ADD'); @@ -69,7 +69,7 @@ describe('group screen tests', () => { }); // after - runs after the last test in order of declaration - after(async() => { + after(async () => { // open browser await browser.newUser(); await browser.url(`/`); @@ -83,7 +83,9 @@ describe('group screen tests', () => { await groups.click(); // delete the group used in the test - let buttonDeleteGroup = await $('.//*[local-name()="svg" and @id="delete-group-icon-history-test-group"]'); + let buttonDeleteGroup = await $( + './/*[local-name()="svg" and @id="delete-group-icon-history-test-group"]' + ); await buttonDeleteGroup.click(); let modalDeleteButton = await $('button*=Delete'); await modalDeleteButton.click(); @@ -110,16 +112,21 @@ describe('group screen tests', () => { // input did not change expect(await addMemberInput.getValue()).toBe('invalidusername'); // input is not bold - let fontWeight = await addMemberInput.getCSSProperty('font-weight').value; + let fontWeight = await addMemberInput.getCSSProperty('font-weight') + .value; expect(fontWeight).toBeUndefined(); // submit (item in dropdown is not selected) let submitButton = await $('button*=Submit'); await submitButton.click(); // verify error message let errorMessage = await $('div[data-testid="error-message"]'); - expect(await errorMessage.getText()).toBe('Member must be selected in the dropdown or member input field must be empty.'); + expect(await errorMessage.getText()).toBe( + 'Member must be selected in the dropdown or member input field must be empty.' + ); // clear input - let clearInput = await $(`.//*[local-name()="svg" and @data-wdio="clear-input"]`); + let clearInput = await $( + `.//*[local-name()="svg" and @data-wdio="clear-input"]` + ); await clearInput.click(); // add valid input await addMemberInput.addValue('unix.yahoo'); @@ -132,4 +139,4 @@ describe('group screen tests', () => { fontWeight = await addMemberInput.getCSSProperty('font-weight'); expect(fontWeight.value === 700).toBe(true); }); -}) +}); diff --git a/ui/src/api.js b/ui/src/api.js index 42c3afda5ab..c3968df8331 100644 --- a/ui/src/api.js +++ b/ui/src/api.js @@ -40,7 +40,7 @@ const Api = (req) => { return new Promise((resolve, reject) => { fetchr .read('domain-role-member') - .params({ expand: true }) + .params({ expand: true }) .end((err, data) => { if (err) { reject(err); diff --git a/ui/src/mock/MockData.js b/ui/src/mock/MockData.js index f54a273b365..7eb6b15eac9 100644 --- a/ui/src/mock/MockData.js +++ b/ui/src/mock/MockData.js @@ -20,10 +20,10 @@ export const getPrincipalRoles_response = { memberRoles: [ { domainName: 'athens', roleName: 'somerole' }, { domainName: 'athens.ci', roleName: 'somerole' }, - ] -} + ], +}; export const listUserDomains_response = { - ...getPrincipalRoles_response, + ...getPrincipalRoles_response, prefix: ['athens', 'athens.ci'], }; diff --git a/ui/src/pages/workflow/domain.js b/ui/src/pages/workflow/domain.js index 0d44af3a67c..26b120479f8 100644 --- a/ui/src/pages/workflow/domain.js +++ b/ui/src/pages/workflow/domain.js @@ -212,7 +212,10 @@ class WorkflowDomain extends React.Component { { let domainsToReturn = []; @@ -282,12 +281,12 @@ const transformDomainListResult = (domainsData) => { // processing non-admin domains separately because user can be an admin of same domain only once // but can be non-admin member of same domain via multiple roles/groups - domainsData.memberRoles.forEach(role => { + domainsData.memberRoles.forEach((role) => { if (role.roleName === 'admin') { // create admin domain object adminDomains.add({ name: role.domainName, - adminDomain: true + adminDomain: true, }); // remove admin domain from list of non admin domains const adminDomainIndex = nonAdminDomains.indexOf(role.domainName); @@ -299,16 +298,15 @@ const transformDomainListResult = (domainsData) => { domainsToReturn.push(...adminDomains); // create and add non admin domains - nonAdminDomains.forEach(domain => { + nonAdminDomains.forEach((domain) => { domainsToReturn.push({ name: domain, - adminDomain: false - }) - }) + adminDomain: false, + }); + }); // sorting domains alphabetically domainsToReturn.sort((a, b) => a.name.localeCompare(b.name)); return domainsToReturn; }; -