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

ui - display all domains that reference current user #2789

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions ui/src/__tests__/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand All @@ -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);
},
Expand Down
53 changes: 35 additions & 18 deletions ui/src/__tests__/components/utils/ReviewUtils.test.js
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only formatting change

Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ 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();
});

describe('DomainSettingsPage', () => {
it('should render', async () => {
let domains = [];
domains.push({ name: 'athens' });
domains.push({ name: 'athens.ci' });
let query = {
domain: 'dom',
};
Expand Down Expand Up @@ -63,7 +61,7 @@ describe('DomainSettingsPage', () => {
),
listUserDomains: jest.fn().mockReturnValue(
new Promise((resolve, reject) => {
resolve(domains);
resolve(listUserDomains_response);
})
),
};
Expand Down
6 changes: 2 additions & 4 deletions ui/src/__tests__/pages/domain/[domain]/group.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
mockAllDomainDataApiCalls,
renderWithRedux,
} from '../../../../tests_utils/ComponentsTestUtils';
import { listUserDomains_response } from '../../../../mock/MockData';

afterEach(() => {
MockApi.cleanMockApi();
Expand All @@ -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',
};
Expand Down Expand Up @@ -69,7 +67,7 @@ describe('GroupPage', () => {
),
listUserDomains: jest.fn().mockReturnValue(
new Promise((resolve, reject) => {
resolve(domains);
resolve(listUserDomains_response);
})
),
getGroups: jest.fn().mockReturnValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ import {
renderWithRedux,
} from '../../../../../../tests_utils/ComponentsTestUtils';
import MockApi from '../../../../../../mock/MockApi';
import { listUserDomains_response } from '../../../../../../mock/MockData';

afterEach(() => {
MockApi.cleanMockApi();
});

describe('GroupMemberPage', () => {
it('should render', async () => {
let domains = [];
domains.push({ name: 'athens' });
domains.push({ name: 'athens.ci' });
let query = {
domain: 'dom',
};
Expand Down Expand Up @@ -67,7 +65,7 @@ describe('GroupMemberPage', () => {
),
listUserDomains: jest.fn().mockReturnValue(
new Promise((resolve, reject) => {
resolve(domains);
resolve(listUserDomains_response);
})
),
getDomainRoleMembers: jest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
renderWithRedux,
} from '../../../../../../tests_utils/ComponentsTestUtils';
import MockApi from '../../../../../../mock/MockApi';
import { listUserDomains_response } from '../../../../../../mock/MockData';

describe('GroupReviewPage', () => {
beforeEach(() => {
Expand All @@ -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',
};
Expand Down Expand Up @@ -69,7 +67,7 @@ describe('GroupReviewPage', () => {
),
listUserDomains: jest.fn().mockReturnValue(
new Promise((resolve, reject) => {
resolve(domains);
resolve(listUserDomains_response);
})
),
getGroup: jest.fn().mockReturnValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ import {
mockAllDomainDataApiCalls,
renderWithRedux,
} from '../../../../../../tests_utils/ComponentsTestUtils';
import { listUserDomains_response } from '../../../../../../mock/MockData';

afterEach(() => {
MockApi.cleanMockApi();
});

describe('GroupRolesPage', () => {
it('should render', async () => {
let domains = [];
domains.push({ name: 'athens' });
domains.push({ name: 'athens.ci' });
let query = {
domain: 'dom',
};
Expand Down Expand Up @@ -66,7 +64,7 @@ describe('GroupRolesPage', () => {
),
listUserDomains: jest.fn().mockReturnValue(
new Promise((resolve, reject) => {
resolve(domains);
resolve(listUserDomains_response);
})
),
getGroup: jest.fn().mockReturnValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
mockAllDomainDataApiCalls,
renderWithRedux,
} from '../../../../../../tests_utils/ComponentsTestUtils';
import { listUserDomains_response } from '../../../../../../mock/MockData';

afterEach(() => {
MockApi.cleanMockApi();
Expand All @@ -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',
};
Expand Down Expand Up @@ -70,7 +68,7 @@ describe('GroupSettingPage', () => {
),
listUserDomains: jest.fn().mockReturnValue(
new Promise((resolve, reject) => {
resolve(domains);
resolve(listUserDomains_response);
})
),
getGroup: jest.fn().mockReturnValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
configApiGroups,
singleApiGroup,
} from '../../../../../redux/config/group.test';
import { listUserDomains_response } from '../../../../../../mock/MockData';

describe('Groups Tag Page', () => {
afterEach(() => {
Expand All @@ -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 = {
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ import {
renderWithRedux,
} from '../../../../tests_utils/ComponentsTestUtils';
import MockApi from '../../../../mock/MockApi';
import { listUserDomains_response } from '../../../../mock/MockData';

afterEach(() => {
MockApi.cleanMockApi();
});

describe('MicrosegmentationPage', () => {
it('should render', async () => {
let domains = [];
domains.push({ name: 'athens' });
domains.push({ name: 'athens.ci' });
let query = {
domain: 'dom',
};
Expand Down Expand Up @@ -65,7 +63,7 @@ describe('MicrosegmentationPage', () => {
),
listUserDomains: jest.fn().mockReturnValue(
new Promise((resolve, reject) => {
resolve(domains);
resolve(listUserDomains_response);
})
),
getPolicies: jest.fn().mockReturnValue(
Expand Down
6 changes: 2 additions & 4 deletions ui/src/__tests__/pages/domain/[domain]/policy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
renderWithRedux,
} from '../../../../tests_utils/ComponentsTestUtils';
import MockApi from '../../../../mock/MockApi';
import { listUserDomains_response } from '../../../../mock/MockData';

afterEach(() => {
MockApi.cleanMockApi();
Expand All @@ -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 = {
Expand Down Expand Up @@ -74,7 +72,7 @@ describe('PolicyPage', () => {
),
listUserDomains: jest.fn().mockReturnValue(
new Promise((resolve, reject) => {
resolve(domains);
resolve(listUserDomains_response);
})
),
getPolicies: jest.fn().mockReturnValue(
Expand Down
Loading
Loading