From 29a422cfc9e70752101693aa575759f0e3a3ec01 Mon Sep 17 00:00:00 2001 From: Aryan Swaroop Date: Sat, 28 Dec 2024 17:33:12 +0530 Subject: [PATCH 1/2] Fixed Bug #2455 --- src/screens/UserPortal/People/People.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/screens/UserPortal/People/People.tsx b/src/screens/UserPortal/People/People.tsx index 4904e75b20..216f5b3144 100644 --- a/src/screens/UserPortal/People/People.tsx +++ b/src/screens/UserPortal/People/People.tsx @@ -28,7 +28,7 @@ interface InterfaceMember { image: string; _id: string; email: string; - userType: string; + __typename: string; } /** @@ -243,7 +243,7 @@ export default function people(): JSX.Element { image: member.image, id: member._id, email: member.email, - role: member.userType, + role: member.__typename, sno: (index + 1).toString(), }; return ; From 6ce43faafa7753e23950ff2b29d49ab2bbd5a868 Mon Sep 17 00:00:00 2001 From: Aryan Swaroop Date: Tue, 31 Dec 2024 14:56:10 +0530 Subject: [PATCH 2/2] Added test for interface --- src/screens/UserPortal/People/People.spec.tsx | 57 +++++++++++++++++++ src/screens/UserPortal/People/People.tsx | 2 +- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/screens/UserPortal/People/People.spec.tsx b/src/screens/UserPortal/People/People.spec.tsx index 11051538db..51fb5d2767 100644 --- a/src/screens/UserPortal/People/People.spec.tsx +++ b/src/screens/UserPortal/People/People.spec.tsx @@ -11,6 +11,7 @@ import { Provider } from 'react-redux'; import { store } from 'state/store'; import i18nForTest from 'utils/i18nForTest'; import { StaticMockLink } from 'utils/StaticMockLink'; +import type { InterfaceMember } from './People'; import People from './People'; import userEvent from '@testing-library/user-event'; import { vi } from 'vitest'; @@ -167,6 +168,62 @@ describe('Testing People Screen [User Portal]', () => { expect(screen.queryAllByText('Noble Mittal')).not.toBe([]); }); + function compareProperties( + expectedProps: string[], + actualObject: object, + ): boolean { + const actualProps = Object.keys(actualObject); + return expectedProps.every((prop) => actualProps.includes(prop)); + } + + describe('InterfaceMember properties comparison', () => { + it('should have all required properties', () => { + const expectedProperties = [ + 'firstName', + 'lastName', + 'image', + '_id', + 'email', + '__typename', + ]; + + const mockValidData: InterfaceMember = { + firstName: 'John', + lastName: 'Doe', + image: 'https://example.com/john.jpg', + _id: '1', + email: 'john.doe@example.com', + __typename: 'User', + }; + + const result = compareProperties(expectedProperties, mockValidData); + expect(result).toBe(true); + }); + + it('should fail if __typename is replaced with username', () => { + const expectedProperties = [ + 'firstName', + 'lastName', + 'image', + '_id', + 'email', + '__typename', // Expect this property + ]; + + const mockInvalidData = { + firstName: 'John', + lastName: 'Doe', + image: 'https://example.com/john.jpg', + _id: '1', + email: 'john.doe@example.com', + username: 'Member', // Incorrect property + }; + + const result = compareProperties(expectedProperties, mockInvalidData); + expect(result).toBe(false); + }); + }); + it('Search works properly by pressing enter', async () => { render( diff --git a/src/screens/UserPortal/People/People.tsx b/src/screens/UserPortal/People/People.tsx index 216f5b3144..6dfac868da 100644 --- a/src/screens/UserPortal/People/People.tsx +++ b/src/screens/UserPortal/People/People.tsx @@ -22,7 +22,7 @@ interface InterfaceOrganizationCardProps { sno: string; } -interface InterfaceMember { +export interface InterfaceMember { firstName: string; lastName: string; image: string;