From 7bb67a5726ed096499ec5f17d8e66f67b5af6fed Mon Sep 17 00:00:00 2001 From: Vedant Gupta <115912707+im-vedant@users.noreply.github.com> Date: Sat, 28 Dec 2024 23:39:45 +0530 Subject: [PATCH 1/6] Add code coverage disable check to GitHub workflows (#2701) * feat: add script to check for code coverage disable statements * Add code coverage disable check to GitHub workflows * Formatted code_coverage_disable_check.py to comply with all coding and documentation standards. * add functionality in eslint_disable_check.py to run for mutliple directories * removed unnecessary comment * excluded node_modules from eslint disable check * removed all eslint disable statements and code coverage disable statements * Revert "excluded node_modules from eslint disable check" This reverts commit b57503625856a2e5ab57fcdad9d8d8b690c91960. * Revert "removed all eslint disable statements and code coverage disable statements" This reverts commit 62d423246c5820807ce23c170f386b22875b70fc. * excluded node_modules from eslint disable check * code-coverage check runs for only changed files * add tj-actions * add tj actions in check code coverage job * Fix GitHub Actions workflow to identify and pass nearest changed directories to Python script * syntax correction * minor fix * minor fix * minor fix * added repo root * fix error * fix error * added support for checking .ts files for eslint-disable statements * added support for checking .ts files for code coverage disable statements * minor change * Remove test files and ensured that python files follow coding standards * fixes bug * fix error * removed eslint disable command from check for linting errors in modified files step --------- Co-authored-by: im-vedant <194vedantgutpa@gmail.com> Co-authored-by: Peter Harrison <16875803+palisadoes@users.noreply.github.com> --- .../workflows/code_coverage_disable_check.py | 169 ++++++++++++++++++ .github/workflows/eslint_disable_check.py | 95 ++++++---- .github/workflows/pull-request.yml | 30 +++- src/setupTests.ts | 1 - 4 files changed, 260 insertions(+), 35 deletions(-) create mode 100644 .github/workflows/code_coverage_disable_check.py diff --git a/.github/workflows/code_coverage_disable_check.py b/.github/workflows/code_coverage_disable_check.py new file mode 100644 index 0000000000..4a4fd756d0 --- /dev/null +++ b/.github/workflows/code_coverage_disable_check.py @@ -0,0 +1,169 @@ +"""Code Coverage Disable Checker Script. + +Methodology: + + Recursively analyzes TypeScript files in the specified directories or + checks specific files + to ensure they do not contain code coverage disable statements. + + This script enforces proper code coverage practices in the project. + +NOTE: + This script complies with our python3 coding and documentation standards. + It complies with: + + 1) Pylint + 2) Pydocstyle + 3) Pycodestyle + 4) Flake8 + 5) Python Black + +""" + +import os +import re +import argparse +import sys + + +def has_code_coverage_disable(file_path): + """ + Check if a TypeScript file contains code coverage disable statements. + + Args: + file_path (str): Path to the TypeScript file. + + Returns: + bool: True if code coverage disable statement is found, False + otherwise. + """ + code_coverage_disable_pattern = re.compile( + r"""//?\s*istanbul\s+ignore(?:\s+(?:next|-line))?[^\n]*| + /\*\s*istanbul\s+ignore\s+(?:next|-line)\s*\*/""", + re.IGNORECASE, + ) + try: + with open(file_path, "r", encoding="utf-8") as file: + content = file.read() + return bool(code_coverage_disable_pattern.search(content)) + except FileNotFoundError: + print(f"File not found: {file_path}") + return False + except PermissionError: + print(f"Permission denied: {file_path}") + return False + except (IOError, OSError) as e: + print(f"Error reading file {file_path}: {e}") + return False + + +def check_code_coverage(files_or_dirs): + """ + Check TypeScript files for code coverage disable statements. + + Args: + files_or_dirs (list): List of files or directories to check. + + Returns: + bool: True if code coverage disable statement is found, False + otherwise. + """ + code_coverage_found = False + + for item in files_or_dirs: + if os.path.isdir(item): + # If it's a directory, recursively walk through the files in it + for root, _, files in os.walk(item): + if "node_modules" in root: + continue + for file_name in files: + if ( + file_name.endswith(".tsx") + or file_name.endswith(".ts") + and not file_name.endswith(".test.tsx") + and not file_name.endswith(".test.ts") + and not file_name.endswith(".spec.tsx") + and not file_name.endswith(".spec.ts") + ): + file_path = os.path.join(root, file_name) + if has_code_coverage_disable(file_path): + print( + f"""File {file_path} contains code coverage + disable statement.""" + ) + code_coverage_found = True + elif os.path.isfile(item): + # If it's a file, check it directly + if ( + item.endswith(".tsx") + or item.endswith(".ts") + and not item.endswith(".test.tsx") + and not item.endswith(".test.ts") + and not item.endswith(".spec.tsx") + and not item.endswith(".spec.ts") + ): + if has_code_coverage_disable(item): + print( + f"""File {item} contains code coverage disable + statement.""" + ) + code_coverage_found = True + + return code_coverage_found + + +def arg_parser_resolver(): + """Resolve the CLI arguments provided by the user. + + Returns: + result: Parsed argument object + """ + parser = argparse.ArgumentParser() + parser.add_argument( + "--directory", + type=str, + nargs="+", + default=[os.getcwd()], + help="""One or more directories to check for code coverage disable + statements (default: current directory).""", + ) + parser.add_argument( + "--files", + type=str, + nargs="+", + default=[], + help="""One or more files to check directly for code coverage disable + statements (default: check directories).""", + ) + return parser.parse_args() + + +def main(): + """ + Execute the script's main functionality. + + This function serves as the entry point for the script. It performs + the following tasks: + 1. Validates and retrieves the files or directories to check from + command line arguments. + 2. Checks files or directories for code coverage disable statements. + 3. Provides informative messages based on the analysis. + 4. Exits with an error if code coverage disable statements are found. + + Raises: + SystemExit: If an error occurs during execution. + """ + args = arg_parser_resolver() + files_or_dirs = args.files if args.files else args.directory + # Check code coverage in the specified files or directories + code_coverage_found = check_code_coverage(files_or_dirs) + + if code_coverage_found: + print("Code coverage disable check failed. Exiting with error.") + sys.exit(1) + + print("Code coverage disable check completed successfully.") + + +if __name__ == "__main__": + main() diff --git a/.github/workflows/eslint_disable_check.py b/.github/workflows/eslint_disable_check.py index 201b4462b8..ee17fcb220 100644 --- a/.github/workflows/eslint_disable_check.py +++ b/.github/workflows/eslint_disable_check.py @@ -4,13 +4,13 @@ Methodology: - Recursively analyzes TypeScript files in the 'src' directory and its subdirectories - as well as 'setup.ts' files to ensure they do not contain eslint-disable statements. + Recursively analyzes TypeScript files in the specified directory + or checks specific files directly to ensure they do not contain + eslint-disable statements. This script enforces code quality practices in the project. NOTE: - This script complies with our python3 coding and documentation standards. It complies with: @@ -18,14 +18,15 @@ 2) Pydocstyle 3) Pycodestyle 4) Flake8 + 5) Python Black """ - import os import re import argparse import sys + def has_eslint_disable(file_path): """ Check if a TypeScript file contains eslint-disable statements. @@ -36,43 +37,65 @@ def has_eslint_disable(file_path): Returns: bool: True if eslint-disable statement is found, False otherwise. """ - eslint_disable_pattern = re.compile(r'//\s*eslint-disable(?:-next-line|-line)?', re.IGNORECASE) - + eslint_disable_pattern = re.compile( + r"""\/\/\s*eslint-disable(?:-next-line + |-line)?[^\n]*|\/\*\s*eslint-disable[^\*]*\*\/""", + re.IGNORECASE, + ) + try: - with open(file_path, 'r', encoding='utf-8') as file: + with open(file_path, "r", encoding="utf-8") as file: content = file.read() return bool(eslint_disable_pattern.search(content)) - except Exception as e: + except FileNotFoundError: + print(f"File not found: {file_path}") + return False + except PermissionError: + print(f"Permission denied: {file_path}") + return False + except (IOError, OSError) as e: print(f"Error reading file {file_path}: {e}") return False -def check_eslint(directory): + +def check_eslint(files_or_directories): """ - Recursively check TypeScript files for eslint-disable statements in the 'src' directory. + Check TypeScript files for eslint-disable statements. Args: - directory (str): Path to the directory. + files_or_directories (list): List of files or directories to check. Returns: bool: True if eslint-disable statement is found, False otherwise. """ eslint_found = False - for root, dirs, files in os.walk(os.path.join(directory, 'src')): - for file_name in files: - if file_name.endswith('.tsx') and not file_name.endswith('.test.tsx'): - file_path = os.path.join(root, file_name) - if has_eslint_disable(file_path): - print(f'File {file_path} contains eslint-disable statement.') + for item in files_or_directories: + if os.path.isfile(item): + # If it's a file, directly check it + if item.endswith(".ts") or item.endswith(".tsx"): + if has_eslint_disable(item): + print(f"File {item} contains eslint-disable statement.") eslint_found = True - - setup_path = os.path.join(directory, 'setup.ts') - if os.path.exists(setup_path) and has_eslint_disable(setup_path): - print(f'Setup file {setup_path} contains eslint-disable statement.') - eslint_found = True + elif os.path.isdir(item): + # If it's a directory, walk through it and check all + # .ts and .tsx files + for root, _, files in os.walk(item): + if "node_modules" in root: + continue + for file_name in files: + if file_name.endswith(".ts") or file_name.endswith(".tsx"): + file_path = os.path.join(root, file_name) + if has_eslint_disable(file_path): + print( + f"""File {file_path} contains eslint-disable + statement.""" + ) + eslint_found = True return eslint_found + def arg_parser_resolver(): """Resolve the CLI arguments provided by the user. @@ -80,21 +103,32 @@ def arg_parser_resolver(): result: Parsed argument object """ parser = argparse.ArgumentParser() + parser.add_argument( + "--files", + type=str, + nargs="+", + default=[], + help="""List of files to check for eslint disable + statements (default: None).""", + ) parser.add_argument( "--directory", type=str, - default=os.getcwd(), - help="Path to the directory to check (default: current directory)" + nargs="+", + default=[os.getcwd()], + help="""One or more directories to check for eslint disable + statements (default: current directory).""", ) return parser.parse_args() + def main(): """ Execute the script's main functionality. This function serves as the entry point for the script. It performs the following tasks: - 1. Validates and retrieves the directory to check from + 1. Validates and retrieves the files and directories to check from command line arguments. 2. Recursively checks TypeScript files for eslint-disable statements. 3. Provides informative messages based on the analysis. @@ -105,12 +139,10 @@ def main(): """ args = arg_parser_resolver() - if not os.path.exists(args.directory): - print(f"Error: The specified directory '{args.directory}' does not exist.") - sys.exit(1) - - # Check eslint in the specified directory - eslint_found = check_eslint(args.directory) + # Determine whether to check files or directories based on the arguments + files_or_directories = args.files if args.files else args.directory + # Check eslint in the specified files or directories + eslint_found = check_eslint(files_or_directories) if eslint_found: print("ESLint-disable check failed. Exiting with error.") @@ -118,5 +150,6 @@ def main(): print("ESLint-disable check completed successfully.") + if __name__ == "__main__": main() diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 95572a6d81..4708e39869 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -59,7 +59,7 @@ jobs: if: steps.changed-files.outputs.only_changed != 'true' env: CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} - run: npx eslint ${CHANGED_FILES} && python .github/workflows/eslint_disable_check.py + run: npx eslint ${CHANGED_FILES} - name: Check for TSDoc comments run: npm run check-tsdoc # Run the TSDoc check script @@ -181,6 +181,30 @@ jobs: - name: Checkout code uses: actions/checkout@v4 + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v45 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.9 + + - name: Run Python script + run: | + python .github/workflows/eslint_disable_check.py --files ${{ steps.changed-files.outputs.all_changed_files }} + + Check-Code-Coverage-Disable: + name: Check for code coverage disable + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v45 + - name: Set up Python uses: actions/setup-python@v5 with: @@ -188,12 +212,12 @@ jobs: - name: Run Python script run: | - python .github/workflows/eslint_disable_check.py + python .github/workflows/code_coverage_disable_check.py --files ${{ steps.changed-files.outputs.all_changed_files }} Test-Application: name: Test Application runs-on: ubuntu-latest - needs: [Code-Quality-Checks, Check-ESlint-Disable] + needs: [Code-Quality-Checks, Check-ESlint-Disable,Check-Code-Coverage-Disable] steps: - name: Checkout the Repository uses: actions/checkout@v4 diff --git a/src/setupTests.ts b/src/setupTests.ts index d204b3ddc9..19c34e040a 100644 --- a/src/setupTests.ts +++ b/src/setupTests.ts @@ -3,7 +3,6 @@ // expect(element).toHaveTextContent(/react/i) // learn more: https://github.com/testing-library/jest-dom import '@testing-library/jest-dom'; - global.fetch = jest.fn(); import { format } from 'util'; From a788c5ec2d65d5bf3f50bc89bba74aa29672a0d9 Mon Sep 17 00:00:00 2001 From: Nikhil Raj <125121367+hustlernik@users.noreply.github.com> Date: Sat, 28 Dec 2024 23:44:22 +0530 Subject: [PATCH 2/6] [REFACTOR] CSS for Events.tsx (#2998) * refactor css for Events.tsx * css variable * Update src/style/app.module.css Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * css optimise --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../UserPortal/Events/Events.module.css | 156 ------------------ src/screens/UserPortal/Events/Events.tsx | 28 ++-- src/style/app.module.css | 155 +++++++++++++++++ 3 files changed, 169 insertions(+), 170 deletions(-) delete mode 100644 src/screens/UserPortal/Events/Events.module.css diff --git a/src/screens/UserPortal/Events/Events.module.css b/src/screens/UserPortal/Events/Events.module.css deleted file mode 100644 index eadbf63d0f..0000000000 --- a/src/screens/UserPortal/Events/Events.module.css +++ /dev/null @@ -1,156 +0,0 @@ -.borderNone { - border: none; -} - -.colorWhite { - color: white; -} - -.backgroundWhite { - background-color: white; -} - -.maxWidth { - max-width: 800px; -} - -.mainContainer { - margin-top: 2rem; - width: 50%; - flex-grow: 3; - max-height: 100%; - overflow: auto; -} - -.content { - height: fit-content; - min-height: calc(100% - 40px); -} -.selectType { - border-radius: 10px; -} -.dropdown__item { - text-overflow: ellipsis; - overflow: hidden; - white-space: nowrap; -} - -.gap { - gap: 20px; -} - -.paddingY { - padding: 30px 0px; -} - -.colorPrimary { - background: #31bb6b; - color: white; -} - -.eventActionsContainer { - display: flex; - flex-direction: row; - gap: 15px; -} - -.datePicker { - border-radius: 10px; - height: 40px; - text-align: center; - background-color: #f2f2f2; - border: none; - width: 100%; -} - -.modalBody { - display: flex; - flex-direction: column; - gap: 10px; -} - -.switchContainer { - display: flex; - align-items: center; -} - -.switches { - display: flex; - flex-direction: row; - gap: 20px; - flex-wrap: wrap; - margin-top: 20px; -} -.titlemodal { - color: #707070; - font-weight: 600; - font-size: 20px; - margin-bottom: 20px; - padding-bottom: 5px; - border-bottom: 3px solid #31bb6b; - width: 65%; -} - -.datediv { - display: flex; - flex-direction: row; - margin-bottom: 15px; -} - -.datebox { - width: 90%; - border-radius: 7px; - border-color: #e8e5e5; - outline: none; - box-shadow: none; - padding-top: 2px; - padding-bottom: 2px; - padding-right: 5px; - padding-left: 5px; - margin-right: 5px; - margin-left: 5px; -} - -.checkboxdiv > label { - margin-right: 50px; -} -.checkboxdiv > label > input { - margin-left: 10px; -} - -.checkboxdiv { - display: flex; -} -.checkboxdiv > div { - width: 50%; -} - -.dispflex { - display: flex; - align-items: center; -} -.dispflex > input { - border: none; - box-shadow: none; - margin-top: 5px; -} - -.greenregbtn { - margin: 1rem 0 0; - margin-top: 15px; - border: 1px solid #e8e5e5; - box-shadow: 0 2px 2px #e8e5e5; - padding: 10px 10px; - border-radius: 5px; - background-color: #31bb6b; - width: 100%; - font-size: 16px; - color: white; - outline: none; - font-weight: 600; - cursor: pointer; - transition: - transform 0.2s, - box-shadow 0.2s; - width: 100%; -} diff --git a/src/screens/UserPortal/Events/Events.tsx b/src/screens/UserPortal/Events/Events.tsx index d3fabf9469..aa8128c9e5 100644 --- a/src/screens/UserPortal/Events/Events.tsx +++ b/src/screens/UserPortal/Events/Events.tsx @@ -19,7 +19,7 @@ import { toast } from 'react-toastify'; import { ViewType } from 'screens/OrganizationEvents/OrganizationEvents'; import { errorHandler } from 'utils/errorHandler'; import useLocalStorage from 'utils/useLocalstorage'; -import styles from './Events.module.css'; +import styles from './../../../style/app.module.css'; /** * Converts a time string to a Dayjs object. @@ -236,7 +236,7 @@ export default function events(): JSX.Element { -

{t('eventDetails')}

+

{t('eventDetails')}

+ + {editChatTitle ? ( +
+ { + setChatName(e.target.value); + }} + /> + { + await updateChat({ + variables: { + input: { + _id: chat._id, + image: selectedImage ? selectedImage : '', + name: chatName, + }, + }, + }); + setEditChatTitle(false); + await chatRefetch(); + }} + /> + { + setEditChatTitle(false); + setChatName(chat.name || ''); + }} + /> +
+ ) : ( +
+

{chat?.name}

+ { + setEditChatTitle(true); + }} + /> +
+ )} + +

+ {chat?.users.length} {t('members')} +

+

{chat?.description}

+ + +
+
+ {chat.users.length} {t('members')} +
+ + {chat.admins.map((admin) => admin._id).includes(userId) && ( + { + openAddUserModal(); + }} + > + {t('addMembers')} + + )} + {chat.users.map( + (user: { + _id: string; + firstName: string; + lastName: string; + }) => ( + +
+ + {user.firstName} {user.lastName} +
+ +
+ {chat.admins + .map((admin) => admin._id) + .includes(user._id) && ( +

Admin

+ )} +
+
+ ), + )} +
+
+ +
+ + + {'Chat'} + + + {allUsersLoading ? ( + <> + + + ) : ( + <> +
+
+ { + const { value } = e.target; + setUserName(value); + }} + /> + + +
+ + + + + + # + {'user'} + {'Chat'} + + + + {console.log(allUsersData)} + {allUsersData && + allUsersData.users.length > 0 && + allUsersData.users.map( + ( + userDetails: InterfaceQueryUserListItem, + index: number, + ) => ( + + + {index + 1} + + + {userDetails.user.firstName + + ' ' + + userDetails.user.lastName} +
+ {userDetails.user.email} +
+ + + +
+ ), + )} +
+
+
+ + )} +
+
+ + ); +} diff --git a/src/components/UserPortal/ChatRoom/ChatRoom.module.css b/src/components/UserPortal/ChatRoom/ChatRoom.module.css index 5fc98351cd..5f89e6122a 100644 --- a/src/components/UserPortal/ChatRoom/ChatRoom.module.css +++ b/src/components/UserPortal/ChatRoom/ChatRoom.module.css @@ -4,8 +4,9 @@ /* background-color: rgba(196, 255, 211, 0.3); */ } -.backgroundWhite { +.sendMessageInput { background-color: white; + border-radius: 12px 0px 0px 12px; } .grey { @@ -152,7 +153,8 @@ } .contactImage { - height: fit-content; + height: 45px !important; + border-radius: 100%; } .senderInfo { @@ -235,6 +237,38 @@ animation-duration: 1s; } +.attachment { + padding: 10px; + background-color: rgb(219, 219, 219); + height: 200px; + display: flex; + align-items: flex-start; + border-radius: 10px; +} + +.attachment img { + height: 100%; + width: 100%; + object-fit: cover; + border-radius: 8px; +} + +.messageAttachment { + height: 300px; + width: 300px; + border-radius: 10px; + object-fit: cover; + margin: 10px 0px 10px 10px; +} + +.addAttachmentBtn { + border: none; + outline: none; + margin: 0 10px; + background-color: white; + font-size: 20px; +} + @keyframes test { from { background-color: white; diff --git a/src/components/UserPortal/ChatRoom/ChatRoom.spec.tsx b/src/components/UserPortal/ChatRoom/ChatRoom.spec.tsx index fef1b67fa5..ef88baaf4c 100644 --- a/src/components/UserPortal/ChatRoom/ChatRoom.spec.tsx +++ b/src/components/UserPortal/ChatRoom/ChatRoom.spec.tsx @@ -7,21 +7,27 @@ import { fireEvent, waitFor, } from '@testing-library/react'; -import { MockSubscriptionLink, MockedProvider } from '@apollo/react-testing'; +import { MockedProvider, MockSubscriptionLink } from '@apollo/react-testing'; import { I18nextProvider } from 'react-i18next'; import { BrowserRouter } from 'react-router-dom'; import { Provider } from 'react-redux'; import { store } from 'state/store'; import i18nForTest from 'utils/i18nForTest'; -import { CHATS_LIST, CHAT_BY_ID } from 'GraphQl/Queries/PlugInQueries'; import { + CHATS_LIST, + CHAT_BY_ID, + GROUP_CHAT_LIST, + UNREAD_CHAT_LIST, +} from 'GraphQl/Queries/PlugInQueries'; +import { + MARK_CHAT_MESSAGES_AS_READ, MESSAGE_SENT_TO_CHAT, SEND_MESSAGE_TO_CHAT, } from 'GraphQl/Mutations/OrganizationMutations'; import ChatRoom from './ChatRoom'; -import { useLocalStorage } from 'utils/useLocalstorage'; import { StaticMockLink } from 'utils/StaticMockLink'; import { vi } from 'vitest'; +import useLocalStorage from 'utils/useLocalstorage'; /** * Unit tests for the ChatRoom component @@ -58,6 +64,7 @@ const MESSAGE_SENT_TO_CHAT_MOCK = [ _id: '1', }, messageContent: 'Test ', + media: null, replyTo: null, sender: { _id: '64378abd85008f171cf2990d', @@ -83,6 +90,36 @@ const MESSAGE_SENT_TO_CHAT_MOCK = [ _id: '668ec1f1df364e03ac47a151', createdAt: '2024-07-10T17:16:33.248Z', messageContent: 'Test ', + media: null, + chatMessageBelongsTo: { + _id: '1', + }, + replyTo: null, + sender: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: '', + }, + updatedAt: '2024-07-10', + }, + }, + }, + }, + { + request: { + query: MESSAGE_SENT_TO_CHAT, + variables: { + userId: '8', + }, + }, + result: { + data: { + messageSentToChat: { + _id: '668ec1f1df364e03ac47a151', + createdAt: '2024-07-10T17:16:33.248Z', + messageContent: 'Test ', + media: null, chatMessageBelongsTo: { _id: '1', }, @@ -111,6 +148,7 @@ const MESSAGE_SENT_TO_CHAT_MOCK = [ _id: '668ec1f13603ac4697a151', createdAt: '2024-07-10T17:16:33.248Z', messageContent: 'Test ', + media: null, chatMessageBelongsTo: { _id: '1', }, @@ -128,17 +166,15 @@ const MESSAGE_SENT_TO_CHAT_MOCK = [ }, ]; -const CHAT_BY_ID_QUERY_MOCK = [ +const UNREAD_CHAT_LIST_QUERY_MOCK = [ { request: { - query: CHAT_BY_ID, - variables: { - id: '1', - }, + query: UNREAD_CHAT_LIST, + variables: {}, }, result: { data: { - chatById: { + getUnreadChatsByUserId: { _id: '1', createdAt: '2345678903456', isGroup: false, @@ -155,10 +191,12 @@ const CHAT_BY_ID_QUERY_MOCK = [ name: '', messages: [ { - _id: '4', + _id: '345678', createdAt: '345678908765', messageContent: 'Hello', + media: null, replyTo: null, + type: 'STRING', sender: { _id: '2', firstName: 'Test', @@ -184,21 +222,27 @@ const CHAT_BY_ID_QUERY_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), }, }, }, }, { request: { - query: CHAT_BY_ID, + query: UNREAD_CHAT_LIST, variables: { - id: '1', + id: '8', }, }, result: { data: { - chatById: { + getUnreadChatsByUserId: { _id: '1', + createdAt: '2345678903456', isGroup: false, creator: { _id: '64378abd85008f171cf2990d', @@ -211,13 +255,14 @@ const CHAT_BY_ID_QUERY_MOCK = [ }, organization: null, name: '', - createdAt: '2345678903456', messages: [ { - _id: '4', + _id: '345678', createdAt: '345678908765', messageContent: 'Hello', + media: null, replyTo: null, + type: 'STRING', sender: { _id: '2', firstName: 'Test', @@ -243,21 +288,27 @@ const CHAT_BY_ID_QUERY_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), }, }, }, }, { request: { - query: CHAT_BY_ID, + query: UNREAD_CHAT_LIST, variables: { - id: '', + id: '8', }, }, result: { data: { - chatById: { + getUnreadChatsByUserId: { _id: '1', + createdAt: '2345678903456', isGroup: false, creator: { _id: '64378abd85008f171cf2990d', @@ -270,13 +321,14 @@ const CHAT_BY_ID_QUERY_MOCK = [ }, organization: null, name: '', - createdAt: '2345678903456', messages: [ { - _id: '4', + _id: '345678', createdAt: '345678908765', messageContent: 'Hello', + media: null, replyTo: null, + type: 'STRING', sender: { _id: '2', firstName: 'Test', @@ -302,894 +354,5309 @@ const CHAT_BY_ID_QUERY_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), }, }, }, }, -]; - -const CHATS_LIST_MOCK = [ { request: { - query: CHATS_LIST, - variables: { - id: null, - }, + query: UNREAD_CHAT_LIST, + variables: {}, }, result: { data: { - chatsByUserId: [ - { - _id: '65844efc814dd40fgh03db811c4', - isGroup: true, - creator: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', - image: null, - email: 'testsuperadmin@example.com', - createdAt: '2023-04-13T04:53:17.742Z', - __typename: 'User', - }, - organization: { - _id: 'pw3ertyuiophgfre45678', - name: 'rtyu', - }, - createdAt: '2345678903456', - name: 'Test Group Chat', - messages: [ - { - _id: '345678', - createdAt: '345678908765', - messageContent: 'Hello', - replyTo: null, - sender: { - _id: '2', - firstName: 'Test', - lastName: 'User', - email: 'test@example.com', - image: '', - }, - }, - ], - users: [ - { - _id: '1', - firstName: 'Disha', - lastName: 'Talreja', - email: 'disha@example.com', - image: '', - }, - { + getUnreadChatsByUserId: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { _id: '2', firstName: 'Test', lastName: 'User', email: 'test@example.com', image: '', }, - { - _id: '3', - firstName: 'Test', - lastName: 'User1', - email: 'test1@example.com', - image: '', - }, - { - _id: '4', - firstName: 'Test', - lastName: 'User2', - email: 'test2@example.com', - image: '', - }, - { - _id: '5', - firstName: 'Test', - lastName: 'User4', - email: 'test4@example.com', - image: '', - }, - ], - }, - { - _id: '65844efc814ddgh4003db811c4', - isGroup: true, - creator: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', - image: null, - email: 'testsuperadmin@example.com', - createdAt: '2023-04-13T04:53:17.742Z', - __typename: 'User', }, - organization: { - _id: 'pw3ertyuiophgfre45678', - name: 'rtyu', + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', }, - createdAt: '2345678903456', - name: 'Test Group Chat', - messages: [ - { - _id: '345678', - createdAt: '345678908765', - messageContent: 'Hello', - replyTo: null, - sender: { - _id: '2', - firstName: 'Test', - lastName: 'User', - email: 'test@example.com', - image: '', - }, - }, - ], - users: [ - { - _id: '1', - firstName: 'Disha', - lastName: 'Talreja', - email: 'disha@example.com', - image: '', - }, - { - _id: '2', - firstName: 'Test', - lastName: 'User', - email: 'test@example.com', - image: '', - }, - { - _id: '3', - firstName: 'Test', - lastName: 'User1', - email: 'test1@example.com', - image: '', - }, - { - _id: '4', - firstName: 'Test', - lastName: 'User2', - email: 'test2@example.com', - image: '', - }, - { - _id: '5', - firstName: 'Test', - lastName: 'User4', - email: 'test4@example.com', - image: '', - }, - ], - }, - ], + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, }, }, }, { request: { - query: CHATS_LIST, - variables: { - id: '', - }, + query: UNREAD_CHAT_LIST, + variables: {}, }, result: { data: { - chatsByUserId: [ - { - _id: '65844ghjefc814dd4003db811c4', - isGroup: true, - creator: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', - image: null, - email: 'testsuperadmin@example.com', - createdAt: '2023-04-13T04:53:17.742Z', - __typename: 'User', - }, - organization: { - _id: 'pw3ertyuiophgfre45678', - name: 'rtyu', - }, - createdAt: '2345678903456', - name: 'Test Group Chat', - messages: [ - { - _id: '345678', - createdAt: '345678908765', - messageContent: 'Hello', - replyTo: null, - sender: { - _id: '2', - firstName: 'Test', - lastName: 'User', - email: 'test@example.com', - image: '', - }, - }, - ], - users: [ - { - _id: '1', - firstName: 'Disha', - lastName: 'Talreja', - email: 'disha@example.com', - image: '', - }, - { + getUnreadChatsByUserId: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { _id: '2', firstName: 'Test', lastName: 'User', email: 'test@example.com', image: '', }, - { - _id: '3', - firstName: 'Test', - lastName: 'User1', - email: 'test1@example.com', - image: '', - }, - { - _id: '4', - firstName: 'Test', - lastName: 'User2', - email: 'test2@example.com', - image: '', - }, - { - _id: '5', - firstName: 'Test', - lastName: 'User4', - email: 'test4@example.com', - image: '', - }, - ], - }, - { - _id: 'ujhgtrdtyuiop', - isGroup: true, - creator: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', - image: null, - email: 'testsuperadmin@example.com', - createdAt: '2023-04-13T04:53:17.742Z', - __typename: 'User', }, - organization: { - _id: 'pw3ertyuiophgfre45678', - name: 'rtyu', + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', }, - createdAt: '2345678903456', - name: 'Test Group Chat', - messages: [ - { - _id: '345678', - createdAt: '345678908765', - messageContent: 'Hello', - replyTo: null, - sender: { - _id: '2', - firstName: 'Test', - lastName: 'User', - email: 'test@example.com', - image: '', - }, - }, - ], - users: [ - { - _id: '1', - firstName: 'Disha', - lastName: 'Talreja', - email: 'disha@example.com', - image: '', - }, - { + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { _id: '2', firstName: 'Test', lastName: 'User', email: 'test@example.com', image: '', }, - { - _id: '3', - firstName: 'Test', - lastName: 'User1', - email: 'test1@example.com', - image: '', - }, - { - _id: '4', - firstName: 'Test', - lastName: 'User2', - email: 'test2@example.com', - image: '', - }, - { - _id: '5', - firstName: 'Test', - lastName: 'User4', - email: 'test4@example.com', - image: '', - }, - ], - }, - ], + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, }, }, }, { request: { - query: CHATS_LIST, + query: UNREAD_CHAT_LIST, variables: { id: '1', }, }, result: { data: { - chatsByUserId: [ - { - _id: '65844efc814dhjmkdftyd4003db811c4', - isGroup: true, - creator: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', - image: null, - email: 'testsuperadmin@example.com', - createdAt: '2023-04-13T04:53:17.742Z', - __typename: 'User', - }, - organization: { - _id: 'pw3ertyuiophgfre45678', - name: 'rtyu', - }, - createdAt: '2345678903456', - name: 'Test Group Chat', - messages: [ - { - _id: '345678', - createdAt: '345678908765', - messageContent: 'Hello', - replyTo: null, - sender: { - _id: '2', - firstName: 'Test', - lastName: 'User', - email: 'test@example.com', - image: '', - }, - }, - ], - users: [ - { - _id: '1', - firstName: 'Disha', - lastName: 'Talreja', - email: 'disha@example.com', - image: '', - }, - { + getUnreadChatsByUserId: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { _id: '2', firstName: 'Test', lastName: 'User', email: 'test@example.com', image: '', }, - { - _id: '3', - firstName: 'Test', - lastName: 'User1', - email: 'test1@example.com', - image: '', - }, - { - _id: '4', - firstName: 'Test', - lastName: 'User2', - email: 'test2@example.com', - image: '', - }, - { - _id: '5', - firstName: 'Test', - lastName: 'User4', - email: 'test4@example.com', - image: '', - }, - ], - }, - { - _id: '65844ewsedrffc814dd4003db811c4', - isGroup: true, - creator: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', - image: null, - email: 'testsuperadmin@example.com', - createdAt: '2023-04-13T04:53:17.742Z', - __typename: 'User', }, - organization: { - _id: 'pw3ertyuiophgfre45678', - name: 'rtyu', + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', }, - createdAt: '2345678903456', - name: 'Test Group Chat', - messages: [ - { - _id: '345678', - createdAt: '345678908765', - messageContent: 'Hello', - replyTo: null, - sender: { - _id: '2', - firstName: 'Test', - lastName: 'User', - email: 'test@example.com', - image: '', - }, - }, - ], - users: [ - { - _id: '1', - firstName: 'Disha', - lastName: 'Talreja', - email: 'disha@example.com', - image: '', - }, - { + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { _id: '2', firstName: 'Test', lastName: 'User', email: 'test@example.com', image: '', }, - { - _id: '3', - firstName: 'Test', - lastName: 'User1', - email: 'test1@example.com', - image: '', - }, - { - _id: '4', + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', firstName: 'Test', - lastName: 'User2', - email: 'test2@example.com', + lastName: 'User', + email: 'test@example.com', image: '', }, - { - _id: '5', + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', firstName: 'Test', - lastName: 'User4', - email: 'test4@example.com', + lastName: 'User', + email: 'test@example.com', image: '', }, - ], - }, - ], + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '8', + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '8', + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '8', + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, +]; + +const GROUP_CHAT_LIST_QUERY_MOCK = [ + { + request: { + query: GROUP_CHAT_LIST, + variables: { + id: '', + }, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, +]; + +const CHAT_BY_ID_QUERY_MOCK = [ + { + request: { + query: CHAT_BY_ID, + variables: { + id: '1', + }, + }, + result: { + data: { + chatById: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '4', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + }, + }, + }, + }, + }, + { + request: { + query: CHAT_BY_ID, + variables: { + id: '1', + }, + }, + result: { + data: { + chatById: { + _id: '1', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + createdAt: '2345678903456', + messages: [ + { + _id: '4', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + }, + }, + }, + }, + }, + { + request: { + query: CHAT_BY_ID, + variables: { + id: '', + }, + }, + result: { + data: { + chatById: { + _id: '1', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + createdAt: '2345678903456', + messages: [ + { + _id: '4', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + }, + }, + }, + }, + }, +]; + +const CHATS_LIST_MOCK = [ + { + request: { + query: CHATS_LIST, + variables: { + id: '8', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40fgh03db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '8', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40fgh03db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '8', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40fgh03db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40fgh03db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40fgh03db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40fgh03db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40fgh03db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40fgh03db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '2', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40fgh03db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }), + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '2', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40fgh03db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '2', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40fgh03db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844ghjefc814dd4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _id: 'ujhgtrdtyuiop', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dhjmkdftyd4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _id: '65844ewsedrffc814dd4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }), + }, + ], + }, + }, + }, +]; + +const GROUP_CHAT_BY_ID_QUERY_MOCK = [ + { + request: { + query: CHAT_BY_ID, + variables: { + id: '', + }, + }, + result: { + data: { + chatById: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '2', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }), + }, + }, + }, + }, + { + request: { + query: CHAT_BY_ID, + variables: { + id: '1', + }, + }, + result: { + data: { + chatById: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }), + }, + }, + }, + }, + { + request: { + query: CHAT_BY_ID, + variables: { + id: '1', + }, + }, + result: { + data: { + chatById: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }), + }, + }, + }, + }, + { + request: { + query: CHAT_BY_ID, + variables: { + id: '1', + }, + }, + result: { + data: { + chatById: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '1', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + }, + }, + }, + }, + { + request: { + query: CHAT_BY_ID, + variables: { + id: '1', + }, + }, + result: { + data: { + chatById: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '1', + createdAt: '345678908765', + messageContent: 'Hello', + media: '', + replyTo: null, + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + }, + }, + }, + }, +]; + +const SEND_MESSAGE_TO_CHAT_MOCK = [ + { + request: { + query: SEND_MESSAGE_TO_CHAT, + variables: { + chatId: '1', + replyTo: '4', + messageContent: 'Test reply message', + media: 'https://test.com/image.jpg', + }, + }, + result: { + data: { + sendMessageToChat: { + _id: '668ec1f1364e03ac47a151', + createdAt: '2024-07-10T17:16:33.248Z', + messageContent: 'Test ', + media: null, + replyTo: null, + sender: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: '', + }, + updatedAt: '2024-07-10', + }, + }, + }, + }, + { + request: { + query: SEND_MESSAGE_TO_CHAT, + variables: { + chatId: '1', + replyTo: '4', + messageContent: 'Test reply message', + media: '', + }, + }, + result: { + data: { + sendMessageToChat: { + _id: '668ec1f1364e03ac47a151', + createdAt: '2024-07-10T17:16:33.248Z', + messageContent: 'Test ', + media: '', + replyTo: null, + sender: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: '', + }, + updatedAt: '2024-07-10', + }, + }, + }, + }, + { + request: { + query: SEND_MESSAGE_TO_CHAT, + variables: { + chatId: '1', + replyTo: '1', + messageContent: 'Test reply message', + }, + }, + result: { + data: { + sendMessageToChat: { + _id: '668ec1f1364e03ac47a151', + createdAt: '2024-07-10T17:16:33.248Z', + messageContent: 'Test ', + media: null, + replyTo: null, + sender: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: '', + }, + updatedAt: '2024-07-10', + }, + }, + }, + }, + { + request: { + query: SEND_MESSAGE_TO_CHAT, + variables: { + chatId: '1', + replyTo: undefined, + messageContent: 'Hello', + media: '', + }, + }, + result: { + data: { + sendMessageToChat: { + _id: '668ec1f1364e03ac47a151', + createdAt: '2024-07-10T17:16:33.248Z', + messageContent: 'Test ', + media: null, + replyTo: null, + sender: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: '', + }, + updatedAt: '2024-07-10', + }, + }, + }, + }, + { + request: { + query: SEND_MESSAGE_TO_CHAT, + variables: { + chatId: '1', + replyTo: '345678', + messageContent: 'Test reply message', + media: '', + }, + }, + result: { + data: { + sendMessageToChat: { + _id: '668ec1f1364e03ac47a151', + createdAt: '2024-07-10T17:16:33.248Z', + messageContent: 'Test ', + media: null, + replyTo: null, + sender: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: '', + }, + updatedAt: '2024-07-10', + }, + }, + }, + }, + { + request: { + query: SEND_MESSAGE_TO_CHAT, + variables: { + chatId: '1', + replyTo: undefined, + messageContent: 'Test message', + media: '', + }, + }, + result: { + data: { + sendMessageToChat: { + _id: '668ec1f1364e03ac47a151', + createdAt: '2024-07-10T17:16:33.248Z', + messageContent: 'Test ', + media: null, + replyTo: null, + sender: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: '', + }, + updatedAt: '2024-07-10', + }, + }, + }, + }, + { + request: { + query: SEND_MESSAGE_TO_CHAT, + variables: { + chatId: '1', + replyTo: undefined, + messageContent: 'Test reply message', + media: '', + }, + }, + result: { + data: { + sendMessageToChat: { + _id: '668ec1f1364e03ac47a151', + createdAt: '2024-07-10T17:16:33.248Z', + messageContent: 'Test ', + media: null, + replyTo: null, + sender: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: '', + }, + updatedAt: '2024-07-10', + }, + }, + }, + }, +]; + +const MARK_CHAT_MESSAGES_AS_READ_MOCK = [ + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: null, + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '8', + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '8', + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '8', + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '8', + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '8', + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '8', + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '8', + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '8', + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '8', + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, }, }, }, -]; - -const GROUP_CHAT_BY_ID_QUERY_MOCK = [ { request: { - query: CHAT_BY_ID, + query: MARK_CHAT_MESSAGES_AS_READ, variables: { - id: '', + userId: '8', + chatId: '1', }, }, result: { data: { - chatById: { - _id: '65844efc814dd4003db811c4', - isGroup: true, - creator: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', - image: null, - email: 'testsuperadmin@example.com', - createdAt: '2023-04-13T04:53:17.742Z', - __typename: 'User', - }, - organization: { - _id: 'pw3ertyuiophgfre45678', - name: 'rtyu', - }, - createdAt: '2345678903456', - name: 'Test Group Chat', - messages: [ - { - _id: '2', - createdAt: '345678908765', - messageContent: 'Hello', - replyTo: null, - sender: { - _id: '2', - firstName: 'Test', - lastName: 'User', - email: 'test@example.com', - image: '', - }, - }, - ], - users: [ - { - _id: '1', - firstName: 'Disha', - lastName: 'Talreja', - email: 'disha@example.com', - image: '', - }, - { - _id: '2', - firstName: 'Test', - lastName: 'User', - email: 'test@example.com', - image: '', - }, - { - _id: '3', - firstName: 'Test', - lastName: 'User1', - email: 'test1@example.com', - image: '', - }, - { - _id: '4', - firstName: 'Test', - lastName: 'User2', - email: 'test2@example.com', - image: '', - }, - { - _id: '5', - firstName: 'Test', - lastName: 'User4', - email: 'test4@example.com', - image: '', - }, - ], + markChatMessagesAsRead: { + _id: '1', }, }, }, }, { request: { - query: CHAT_BY_ID, + query: MARK_CHAT_MESSAGES_AS_READ, variables: { - id: '1', + userId: '8', + chatId: '1', }, }, result: { data: { - chatById: { - _id: '65844efc814dd4003db811c4', - isGroup: true, - creator: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', - image: null, - email: 'testsuperadmin@example.com', - createdAt: '2023-04-13T04:53:17.742Z', - __typename: 'User', - }, - organization: { - _id: 'pw3ertyuiophgfre45678', - name: 'rtyu', - }, - createdAt: '2345678903456', - name: 'Test Group Chat', - messages: [ - { - _id: '1', - createdAt: '345678908765', - messageContent: 'Hello', - replyTo: null, - sender: { - _id: '2', - firstName: 'Test', - lastName: 'User', - email: 'test@example.com', - image: '', - }, - }, - ], - users: [ - { - _id: '1', - firstName: 'Disha', - lastName: 'Talreja', - email: 'disha@example.com', - image: '', - }, - { - _id: '2', - firstName: 'Test', - lastName: 'User', - email: 'test@example.com', - image: '', - }, - { - _id: '3', - firstName: 'Test', - lastName: 'User1', - email: 'test1@example.com', - image: '', - }, - { - _id: '4', - firstName: 'Test', - lastName: 'User2', - email: 'test2@example.com', - image: '', - }, - { - _id: '5', - firstName: 'Test', - lastName: 'User4', - email: 'test4@example.com', - image: '', - }, - ], + markChatMessagesAsRead: { + _id: '1', }, }, }, }, { request: { - query: CHAT_BY_ID, + query: MARK_CHAT_MESSAGES_AS_READ, variables: { - id: '1', + userId: '8', + chatId: '1', }, }, result: { data: { - chatById: { - _id: '65844efc814dd4003db811c4', - isGroup: true, - creator: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', - image: null, - email: 'testsuperadmin@example.com', - createdAt: '2023-04-13T04:53:17.742Z', - __typename: 'User', - }, - organization: { - _id: 'pw3ertyuiophgfre45678', - name: 'rtyu', - }, - createdAt: '2345678903456', - name: 'Test Group Chat', - messages: [ - { - _id: '1', - createdAt: '345678908765', - messageContent: 'Hello', - replyTo: null, - sender: { - _id: '2', - firstName: 'Test', - lastName: 'User', - email: 'test@example.com', - image: '', - }, - }, - ], - users: [ - { - _id: '1', - firstName: 'Disha', - lastName: 'Talreja', - email: 'disha@example.com', - image: '', - }, - { - _id: '2', - firstName: 'Test', - lastName: 'User', - email: 'test@example.com', - image: '', - }, - { - _id: '3', - firstName: 'Test', - lastName: 'User1', - email: 'test1@example.com', - image: '', - }, - { - _id: '4', - firstName: 'Test', - lastName: 'User2', - email: 'test2@example.com', - image: '', - }, - { - _id: '5', - firstName: 'Test', - lastName: 'User4', - email: 'test4@example.com', - image: '', - }, - ], + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '8', + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: null, + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: null, + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', }, }, }, }, -]; - -const SEND_MESSAGE_TO_CHAT_MOCK = [ { request: { - query: SEND_MESSAGE_TO_CHAT, + query: MARK_CHAT_MESSAGES_AS_READ, variables: { + userId: null, chatId: '1', - replyTo: '4', - messageContent: 'Test reply message', }, }, result: { data: { - sendMessageToChat: { - _id: '668ec1f1364e03ac47a151', - createdAt: '2024-07-10T17:16:33.248Z', - messageContent: 'Test ', - replyTo: null, - sender: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', - image: '', - }, - updatedAt: '2024-07-10', + markChatMessagesAsRead: { + _id: '1', }, }, }, }, { request: { - query: SEND_MESSAGE_TO_CHAT, + query: MARK_CHAT_MESSAGES_AS_READ, variables: { - chatId: '1', - replyTo: '4', - messageContent: 'Test reply message', + userId: null, + chatId: '', }, }, result: { data: { - sendMessageToChat: { - _id: '668ec1f1364e03ac47a151', - createdAt: '2024-07-10T17:16:33.248Z', - messageContent: 'Test ', - replyTo: null, - sender: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', - image: '', - }, - updatedAt: '2024-07-10', + markChatMessagesAsRead: { + _id: '1', }, }, }, }, { request: { - query: SEND_MESSAGE_TO_CHAT, + query: MARK_CHAT_MESSAGES_AS_READ, variables: { + userId: '2', chatId: '1', - replyTo: '1', - messageContent: 'Test reply message', }, }, result: { data: { - sendMessageToChat: { - _id: '668ec1f1364e03ac47a151', - createdAt: '2024-07-10T17:16:33.248Z', - messageContent: 'Test ', - replyTo: null, - sender: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', - image: '', - }, - updatedAt: '2024-07-10', + markChatMessagesAsRead: { + _id: '1', }, }, }, }, { request: { - query: SEND_MESSAGE_TO_CHAT, + query: MARK_CHAT_MESSAGES_AS_READ, variables: { + userId: '2', chatId: '1', - replyTo: undefined, - messageContent: 'Hello', }, }, result: { data: { - sendMessageToChat: { - _id: '668ec1f1364e03ac47a151', - createdAt: '2024-07-10T17:16:33.248Z', - messageContent: 'Test ', - replyTo: null, - sender: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', - image: '', - }, - updatedAt: '2024-07-10', + markChatMessagesAsRead: { + _id: '1', }, }, }, }, { request: { - query: SEND_MESSAGE_TO_CHAT, + query: MARK_CHAT_MESSAGES_AS_READ, variables: { + userId: '2', chatId: '1', - replyTo: '345678', - messageContent: 'Test reply message', }, }, result: { data: { - sendMessageToChat: { - _id: '668ec1f1364e03ac47a151', - createdAt: '2024-07-10T17:16:33.248Z', - messageContent: 'Test ', - replyTo: null, - sender: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', - image: '', - }, - updatedAt: '2024-07-10', + markChatMessagesAsRead: { + _id: '1', }, }, }, }, { request: { - query: SEND_MESSAGE_TO_CHAT, + query: MARK_CHAT_MESSAGES_AS_READ, variables: { - chatId: '1', - replyTo: undefined, - messageContent: 'Test message', + userId: null, + chatId: '', }, }, result: { data: { - sendMessageToChat: { - _id: '668ec1f1364e03ac47a151', - createdAt: '2024-07-10T17:16:33.248Z', - messageContent: 'Test ', - replyTo: null, - sender: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', - image: '', - }, - updatedAt: '2024-07-10', + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '1', + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '1', + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '1', + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', }, }, }, @@ -1198,20 +5665,28 @@ const SEND_MESSAGE_TO_CHAT_MOCK = [ describe('Testing Chatroom Component [User Portal]', () => { window.HTMLElement.prototype.scrollIntoView = vi.fn(); + beforeEach(() => { + vi.clearAllMocks(); + vi.resetModules(); + }); it('Chat room should display fallback content if no chat is active', async () => { const mocks = [ ...MESSAGE_SENT_TO_CHAT_MOCK, ...CHAT_BY_ID_QUERY_MOCK, ...CHATS_LIST_MOCK, + ...GROUP_CHAT_BY_ID_QUERY_MOCK, ...SEND_MESSAGE_TO_CHAT_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ...GROUP_CHAT_LIST_QUERY_MOCK, + ...UNREAD_CHAT_LIST_QUERY_MOCK, ]; render( - + @@ -1227,14 +5702,18 @@ describe('Testing Chatroom Component [User Portal]', () => { ...MESSAGE_SENT_TO_CHAT_MOCK, ...CHAT_BY_ID_QUERY_MOCK, ...CHATS_LIST_MOCK, + ...GROUP_CHAT_BY_ID_QUERY_MOCK, ...SEND_MESSAGE_TO_CHAT_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ...GROUP_CHAT_LIST_QUERY_MOCK, + ...UNREAD_CHAT_LIST_QUERY_MOCK, ]; render( - + @@ -1251,6 +5730,9 @@ describe('Testing Chatroom Component [User Portal]', () => { ...CHATS_LIST_MOCK, ...GROUP_CHAT_BY_ID_QUERY_MOCK, ...SEND_MESSAGE_TO_CHAT_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ...GROUP_CHAT_LIST_QUERY_MOCK, + ...UNREAD_CHAT_LIST_QUERY_MOCK, ]; const link2 = new StaticMockLink(mocks, true); render( @@ -1258,7 +5740,7 @@ describe('Testing Chatroom Component [User Portal]', () => { - + @@ -1281,9 +5763,6 @@ describe('Testing Chatroom Component [User Portal]', () => { act(() => { fireEvent.click(sendBtn); }); - await waitFor(() => { - expect(input.value).toBeFalsy(); - }); const messages = await screen.findAllByTestId('message'); @@ -1336,6 +5815,9 @@ describe('Testing Chatroom Component [User Portal]', () => { ...CHAT_BY_ID_QUERY_MOCK, ...CHATS_LIST_MOCK, ...SEND_MESSAGE_TO_CHAT_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ...GROUP_CHAT_LIST_QUERY_MOCK, + ...UNREAD_CHAT_LIST_QUERY_MOCK, ]; const link2 = new StaticMockLink(mocks, true); render( @@ -1343,7 +5825,7 @@ describe('Testing Chatroom Component [User Portal]', () => { - + @@ -1366,9 +5848,6 @@ describe('Testing Chatroom Component [User Portal]', () => { act(() => { fireEvent.click(sendBtn); }); - await waitFor(() => { - expect(input.value).toBeFalsy(); - }); const messages = await screen.findAllByTestId('message'); @@ -1419,13 +5898,16 @@ describe('Testing Chatroom Component [User Portal]', () => { ...CHAT_BY_ID_QUERY_MOCK, ...CHATS_LIST_MOCK, ...SEND_MESSAGE_TO_CHAT_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ...GROUP_CHAT_LIST_QUERY_MOCK, + ...UNREAD_CHAT_LIST_QUERY_MOCK, ]; render( - + @@ -1439,95 +5921,18 @@ describe('Testing Chatroom Component [User Portal]', () => { ...MESSAGE_SENT_TO_CHAT_MOCK, ...CHAT_BY_ID_QUERY_MOCK, ...CHATS_LIST_MOCK, + ...GROUP_CHAT_BY_ID_QUERY_MOCK, ...SEND_MESSAGE_TO_CHAT_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ...GROUP_CHAT_LIST_QUERY_MOCK, + ...UNREAD_CHAT_LIST_QUERY_MOCK, ]; render( - - - - - , - ); - await wait(); - - const input = (await screen.findByTestId( - 'messageInput', - )) as HTMLInputElement; - - act(() => { - fireEvent.change(input, { target: { value: 'Test message' } }); - }); - expect(input.value).toBe('Test message'); - - const sendBtn = await screen.findByTestId('sendMessage'); - - expect(sendBtn).toBeInTheDocument(); - act(() => { - fireEvent.click(sendBtn); - }); - await waitFor(() => { - expect(input.value).toBeFalsy(); - }); - - const messages = await screen.findAllByTestId('message'); - - expect(messages.length).not.toBe(0); - - act(() => { - fireEvent.mouseOver(messages[0]); - }); - - expect(await screen.findByTestId('moreOptions')).toBeInTheDocument(); - - const moreOptionsBtn = await screen.findByTestId('dropdown'); - act(() => { - fireEvent.click(moreOptionsBtn); - }); - - const replyBtn = await screen.findByTestId('replyBtn'); - - act(() => { - fireEvent.click(replyBtn); - }); - - const replyMsg = await screen.findByTestId('replyMsg'); - - await waitFor(() => { - expect(replyMsg).toBeInTheDocument(); - }); - - act(() => { - fireEvent.change(input, { target: { value: 'Test reply message' } }); - }); - expect(input.value).toBe('Test reply message'); - - const closeReplyBtn = await screen.findByTestId('closeReply'); - - expect(closeReplyBtn).toBeInTheDocument(); - - fireEvent.click(closeReplyBtn); - - await wait(500); - }); - - it('reply to message', async () => { - const mocks = [ - ...MESSAGE_SENT_TO_CHAT_MOCK, - ...CHAT_BY_ID_QUERY_MOCK, - ...CHATS_LIST_MOCK, - ...SEND_MESSAGE_TO_CHAT_MOCK, - ]; - const link2 = new StaticMockLink(mocks, true); - render( - - - - - + @@ -1550,9 +5955,6 @@ describe('Testing Chatroom Component [User Portal]', () => { act(() => { fireEvent.click(sendBtn); }); - await waitFor(() => { - expect(input.value).toBeFalsy(); - }); const messages = await screen.findAllByTestId('message'); @@ -1569,18 +5971,6 @@ describe('Testing Chatroom Component [User Portal]', () => { fireEvent.click(moreOptionsBtn); }); - const replyBtn = await screen.findByTestId('replyBtn'); - - act(() => { - fireEvent.click(replyBtn); - }); - - const replyMsg = await screen.findByTestId('replyMsg'); - - await waitFor(() => { - expect(replyMsg).toBeInTheDocument(); - }); - act(() => { fireEvent.change(input, { target: { value: 'Test reply message' } }); }); @@ -1590,6 +5980,6 @@ describe('Testing Chatroom Component [User Portal]', () => { fireEvent.click(sendBtn); }); - await wait(400); + await wait(500); }); }); diff --git a/src/components/UserPortal/ChatRoom/ChatRoom.tsx b/src/components/UserPortal/ChatRoom/ChatRoom.tsx index 27768dce5a..fd06a47c12 100644 --- a/src/components/UserPortal/ChatRoom/ChatRoom.tsx +++ b/src/components/UserPortal/ChatRoom/ChatRoom.tsx @@ -5,18 +5,31 @@ import { Button, Dropdown, Form, InputGroup } from 'react-bootstrap'; import styles from './ChatRoom.module.css'; import PermContactCalendarIcon from '@mui/icons-material/PermContactCalendar'; import { useTranslation } from 'react-i18next'; -import { CHAT_BY_ID } from 'GraphQl/Queries/PlugInQueries'; +import { CHAT_BY_ID, UNREAD_CHAT_LIST } from 'GraphQl/Queries/PlugInQueries'; +import type { ApolloQueryResult } from '@apollo/client'; import { useMutation, useQuery, useSubscription } from '@apollo/client'; import { + EDIT_CHAT_MESSAGE, + MARK_CHAT_MESSAGES_AS_READ, MESSAGE_SENT_TO_CHAT, SEND_MESSAGE_TO_CHAT, } from 'GraphQl/Mutations/OrganizationMutations'; import useLocalStorage from 'utils/useLocalstorage'; import Avatar from 'components/Avatar/Avatar'; import { MoreVert, Close } from '@mui/icons-material'; +import GroupChatDetails from 'components/GroupChatDetails/GroupChatDetails'; +import { GrAttachment } from 'react-icons/gr'; +import convertToBase64 from 'utils/convertToBase64'; interface InterfaceChatRoomProps { selectedContact: string; + chatListRefetch: ( + variables?: + | Partial<{ + id: string; + }> + | undefined, + ) => Promise>; } /** @@ -59,7 +72,7 @@ type DirectMessage = { } | undefined; messageContent: string; - type: string; + media: string; }; type Chat = { @@ -68,12 +81,20 @@ type Chat = { name?: string; image?: string; messages: DirectMessage[]; + admins: { + _id: string; + firstName: string; + lastName: string; + email: string; + }[]; users: { _id: string; firstName: string; lastName: string; email: string; }[]; + unseenMessagesByUsers: string; + description: string; }; export default function chatRoom(props: InterfaceChatRoomProps): JSX.Element { @@ -93,10 +114,23 @@ export default function chatRoom(props: InterfaceChatRoomProps): JSX.Element { const userId = getItem('userId'); const [chatTitle, setChatTitle] = useState(''); const [chatSubtitle, setChatSubtitle] = useState(''); + const [chatImage, setChatImage] = useState(''); const [newMessage, setNewMessage] = useState(''); const [chat, setChat] = useState(); const [replyToDirectMessage, setReplyToDirectMessage] = useState(null); + const [editMessage, setEditMessage] = useState(null); + const [groupChatDetailsModalisOpen, setGroupChatDetailsModalisOpen] = + useState(false); + + const [attachment, setAttachment] = useState(''); + + const openGroupChatDetails = (): void => { + setGroupChatDetailsModalisOpen(true); + }; + + const toggleGroupChatDetailsModal = (): void => + setGroupChatDetailsModalisOpen(!groupChatDetailsModalisOpen); /** * Handles changes to the new message input field. @@ -114,7 +148,23 @@ export default function chatRoom(props: InterfaceChatRoomProps): JSX.Element { variables: { chatId: props.selectedContact, replyTo: replyToDirectMessage?._id, + media: attachment, + messageContent: newMessage, + }, + }); + + const [editChatMessage] = useMutation(EDIT_CHAT_MESSAGE, { + variables: { + messageId: editMessage?._id, messageContent: newMessage, + chatId: props.selectedContact, + }, + }); + + const [markChatMessagesAsRead] = useMutation(MARK_CHAT_MESSAGES_AS_READ, { + variables: { + chatId: props.selectedContact, + userId: userId, }, }); @@ -124,8 +174,23 @@ export default function chatRoom(props: InterfaceChatRoomProps): JSX.Element { }, }); + // const { refetch: chatListRefetch } = useQuery(CHATS_LIST, { + // variables: { + // id: userId, + // }, + // }); + + const { refetch: unreadChatListRefetch } = useQuery(UNREAD_CHAT_LIST, { + variables: { + id: userId, + }, + }); + useEffect(() => { - chatRefetch(); + markChatMessagesAsRead().then(() => { + props.chatListRefetch(); + unreadChatListRefetch(); + }); }, [props.selectedContact]); useEffect(() => { @@ -135,6 +200,7 @@ export default function chatRoom(props: InterfaceChatRoomProps): JSX.Element { if (chat.isGroup) { setChatTitle(chat.name); setChatSubtitle(`${chat.users.length} members`); + setChatImage(chat.image); } else { const otherUser = chat.users.find( (user: { _id: string }) => user._id !== userId, @@ -142,32 +208,40 @@ export default function chatRoom(props: InterfaceChatRoomProps): JSX.Element { if (otherUser) { setChatTitle(`${otherUser.firstName} ${otherUser.lastName}`); setChatSubtitle(otherUser.email); + setChatImage(otherUser.image); } } } }, [chatData]); const sendMessage = async (): Promise => { - await sendMessageToChat(); + if (editMessage) { + await editChatMessage(); + } else { + await sendMessageToChat(); + } await chatRefetch(); setReplyToDirectMessage(null); setNewMessage(''); + setAttachment(''); + await props.chatListRefetch({ id: userId }); }; useSubscription(MESSAGE_SENT_TO_CHAT, { variables: { userId: userId, }, - onData: (messageSubscriptionData) => { - const chatMessage = messageSubscriptionData.data?.data?.messageSentToChat; - const chatId = chatMessage?.chatMessageBelongsTo?._id; - - if (!chatId) return; - if (chatId === props.selectedContact) { + onData: async (messageSubscriptionData) => { + if ( + messageSubscriptionData?.data.data.messageSentToChat && + messageSubscriptionData?.data.data.messageSentToChat + .chatMessageBelongsTo['_id'] == props.selectedContact + ) { + await markChatMessagesAsRead(); chatRefetch(); - } else { - chatRefetch({ id: chatId }); } + props.chatListRefetch(); + unreadChatListRefetch(); }, }); @@ -177,6 +251,22 @@ export default function chatRoom(props: InterfaceChatRoomProps): JSX.Element { ?.lastElementChild?.scrollIntoView({ block: 'end' }); }); + const fileInputRef = useRef(null); + + const handleAddAttachment = (): void => { + fileInputRef?.current?.click(); + }; + + const handleImageChange = async ( + e: React.ChangeEvent, + ): Promise => { + const file = e.target.files?.[0]; + if (file) { + const base64 = await convertToBase64(file); + setAttachment(base64); + } + }; + return (
- -
+ {chatImage ? ( + {chatTitle} + ) : ( + + )} +
(chat?.isGroup ? openGroupChatDetails() : null)} + className={styles.userDetails} + >

{chatTitle}

{chatSubtitle}

@@ -271,6 +372,13 @@ export default function chatRoom(props: InterfaceChatRoomProps): JSX.Element {
)} + {message.media && ( + attachment + )} {message.messageContent}
@@ -291,7 +399,16 @@ export default function chatRoom(props: InterfaceChatRoomProps): JSX.Element { }} data-testid="replyBtn" > - Reply + {t('reply')} + + { + setEditMessage(message); + setNewMessage(message.messageContent); + }} + data-testid="replyToMessage" + > + Edit @@ -314,6 +431,13 @@ export default function chatRoom(props: InterfaceChatRoomProps): JSX.Element {
+ {!!replyToDirectMessage?._id && (
@@ -349,14 +473,33 @@ export default function chatRoom(props: InterfaceChatRoomProps): JSX.Element {
)} + {attachment && ( +
+ attachment + + +
+ )} + +
); } diff --git a/src/components/UserPortal/ContactCard/ContactCard.module.css b/src/components/UserPortal/ContactCard/ContactCard.module.css index 19d66596c9..59d857efe2 100644 --- a/src/components/UserPortal/ContactCard/ContactCard.module.css +++ b/src/components/UserPortal/ContactCard/ContactCard.module.css @@ -10,8 +10,8 @@ .contactImage { width: 45px !important; - height: auto !important; - border-radius: 10px; + height: 45px !important; + border-radius: 100%; display: flex; align-items: center; justify-content: center; @@ -19,9 +19,10 @@ .contactNameContainer { display: flex; - flex-direction: column; padding: 0px 10px; - justify-content: center; + justify-content: space-between; + align-items: center; + flex-grow: 1; } .grey { @@ -35,3 +36,13 @@ .bgWhite { background-color: white; } + +.lastMessage { + margin-bottom: 0; + font-size: 14px; + color: rgba(163, 163, 163, 0.839); +} + +.unseenMessagesCount { + border-radius: 50%; +} diff --git a/src/components/UserPortal/ContactCard/ContactCard.spec.tsx b/src/components/UserPortal/ContactCard/ContactCard.spec.tsx index 1d32360301..572a38feb7 100644 --- a/src/components/UserPortal/ContactCard/ContactCard.spec.tsx +++ b/src/components/UserPortal/ContactCard/ContactCard.spec.tsx @@ -42,6 +42,8 @@ let props = { image: '', selectedContact: '', type: '', + unseenMessages: 2, + lastMessage: '', setSelectedContact: vi.fn(), setSelectedChatType: vi.fn(), }; diff --git a/src/components/UserPortal/ContactCard/ContactCard.tsx b/src/components/UserPortal/ContactCard/ContactCard.tsx index ef6bf2c9d5..5ec7c9c1d3 100644 --- a/src/components/UserPortal/ContactCard/ContactCard.tsx +++ b/src/components/UserPortal/ContactCard/ContactCard.tsx @@ -1,6 +1,7 @@ import React from 'react'; import styles from './ContactCard.module.css'; import Avatar from 'components/Avatar/Avatar'; +import { Badge } from 'react-bootstrap'; interface InterfaceContactCardProps { id: string; @@ -9,6 +10,8 @@ interface InterfaceContactCardProps { selectedContact: string; setSelectedContact: React.Dispatch>; isGroup: boolean; + unseenMessages: number; + lastMessage: string; } /** @@ -66,7 +69,15 @@ function contactCard(props: InterfaceContactCardProps): JSX.Element { /> )}
- {props.title} +
+ {props.title}{' '} +

{props.lastMessage}

+
+ {!!props.unseenMessages && ( + + {props.unseenMessages} + + )}
diff --git a/src/components/UserPortal/CreateDirectChat/CreateDirectChat.spec.tsx b/src/components/UserPortal/CreateDirectChat/CreateDirectChat.spec.tsx index 5526206708..ccf23a882b 100644 --- a/src/components/UserPortal/CreateDirectChat/CreateDirectChat.spec.tsx +++ b/src/components/UserPortal/CreateDirectChat/CreateDirectChat.spec.tsx @@ -16,9 +16,15 @@ import i18nForTest from 'utils/i18nForTest'; import Chat from '../../../screens/UserPortal/Chat/Chat'; import { CREATE_CHAT, + MARK_CHAT_MESSAGES_AS_READ, MESSAGE_SENT_TO_CHAT, } from 'GraphQl/Mutations/OrganizationMutations'; -import { CHATS_LIST, CHAT_BY_ID } from 'GraphQl/Queries/PlugInQueries'; +import { + CHATS_LIST, + CHAT_BY_ID, + GROUP_CHAT_LIST, + UNREAD_CHAT_LIST, +} from 'GraphQl/Queries/PlugInQueries'; import useLocalStorage from 'utils/useLocalstorage'; import { vi } from 'vitest'; const { setItem } = useLocalStorage(); @@ -347,6 +353,9 @@ const MESSAGE_SENT_TO_CHAT_MOCK = [ data: { messageSentToChat: { _id: '668ec1f1364e03ac47a151', + chatMessageBelongsTo: { + _id: '1', + }, createdAt: '2024-07-10T17:16:33.248Z', messageContent: 'Test ', type: 'STRING', @@ -373,6 +382,9 @@ const MESSAGE_SENT_TO_CHAT_MOCK = [ data: { messageSentToChat: { _id: '668ec1f1df364e03ac47a151', + chatMessageBelongsTo: { + _id: '1', + }, createdAt: '2024-07-10T17:16:33.248Z', messageContent: 'Test ', replyTo: null, @@ -399,6 +411,9 @@ const MESSAGE_SENT_TO_CHAT_MOCK = [ data: { messageSentToChat: { _id: '668ec1f13603ac4697a151', + chatMessageBelongsTo: { + _id: '1', + }, createdAt: '2024-07-10T17:16:33.248Z', messageContent: 'Test ', replyTo: null, @@ -447,6 +462,7 @@ const CHAT_BY_ID_QUERY_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -473,6 +489,19 @@ const CHAT_BY_ID_QUERY_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), }, }, }, @@ -507,6 +536,7 @@ const CHAT_BY_ID_QUERY_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -533,6 +563,19 @@ const CHAT_BY_ID_QUERY_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), }, }, }, @@ -567,6 +610,226 @@ const CHAT_BY_ID_QUERY_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, +]; + +const UNREAD_CHAT_LIST_QUERY_MOCK = [ + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -575,44 +838,2036 @@ const CHAT_BY_ID_QUERY_MOCK = [ email: 'test@example.com', image: '', }, - }, - ], - users: [ - { - _id: '1', - firstName: 'Disha', - lastName: 'Talreja', - email: 'disha@example.com', - image: '', - }, - { - _id: '2', - firstName: 'Test', - lastName: 'User', - email: 'test@example.com', - image: '', - }, - ], - }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, +]; + +const GROUP_CHAT_BY_USER_ID_QUERY_MOCK = [ + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, +]; + +const CHATS_LIST_MOCK = [ + { + request: { + query: CHATS_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40fgh03db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40fgh03db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40fgh03db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40fgh03db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40fgh03db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844ghjefc814dd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: 'ujhgtrdtyuiop', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dhjmkdftyd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844ewsedrffc814dd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], }, }, }, -]; - -const CHATS_LIST_MOCK = [ { request: { query: CHATS_LIST, variables: { - id: null, + id: '1', }, }, result: { data: { chatsByUserId: [ { - _id: '65844efc814dd40fgh03db811c4', + _id: '65844efc814dhjmkdftyd4003db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -634,6 +2889,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -681,10 +2937,27 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, { - _id: '65844efc814ddgh4003db811c4', + _id: '65844ewsedrffc814dd4003db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -706,6 +2979,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -753,6 +3027,22 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, ], }, @@ -762,15 +3052,16 @@ const CHATS_LIST_MOCK = [ request: { query: CHATS_LIST, variables: { - id: '', + id: '1', }, }, result: { data: { chatsByUserId: [ { - _id: '65844ghjefc814dd4003db811c4', + _id: '65844efc814dhjmkdftyd4003db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -789,6 +3080,7 @@ const CHATS_LIST_MOCK = [ messages: [ { _id: '345678', + media: null, createdAt: '345678908765', messageContent: 'Hello', replyTo: null, @@ -839,10 +3131,27 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, { - _id: 'ujhgtrdtyuiop', + _id: '65844ewsedrffc814dd4003db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -864,6 +3173,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -911,6 +3221,22 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, ], }, @@ -929,6 +3255,7 @@ const CHATS_LIST_MOCK = [ { _id: '65844efc814dhjmkdftyd4003db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -950,6 +3277,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -997,10 +3325,27 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, { _id: '65844ewsedrffc814dd4003db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1022,6 +3367,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1069,6 +3415,22 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, ], }, @@ -1087,6 +3449,7 @@ const CHATS_LIST_MOCK = [ { _id: '65844efc814dhjmkdftyd4003db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1108,6 +3471,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1155,10 +3519,27 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, { _id: '65844ewsedrffc814dd4003db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1180,6 +3561,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1227,6 +3609,22 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, ], }, @@ -1247,6 +3645,7 @@ const GROUP_CHAT_BY_ID_QUERY_MOCK = [ chatById: { _id: '65844efc814dd4003db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1268,6 +3667,7 @@ const GROUP_CHAT_BY_ID_QUERY_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1315,6 +3715,22 @@ const GROUP_CHAT_BY_ID_QUERY_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, }, }, @@ -1355,6 +3771,7 @@ const CREATE_CHAT_MUTATION_MOCK = [ messageContent: 'Hello', replyTo: null, type: 'STRING', + media: null, sender: { _id: '2', firstName: 'Test', @@ -1380,12 +3797,114 @@ const CREATE_CHAT_MUTATION_MOCK = [ image: '', }, ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + }), }, }, }, }, ]; +const MARK_CHAT_MESSAGES_AS_READ_MOCK = [ + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: null, + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: null, + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: null, + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: null, + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '1', + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '1', + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, +]; async function wait(ms = 100): Promise { await act(() => { return new Promise((resolve) => { @@ -1419,6 +3938,9 @@ describe('Testing Create Direct Chat Modal [User Portal]', () => { ...CHATS_LIST_MOCK, ...CHAT_BY_ID_QUERY_MOCK, ...CREATE_CHAT_MUTATION_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ...UNREAD_CHAT_LIST_QUERY_MOCK, + ...GROUP_CHAT_BY_USER_ID_QUERY_MOCK, ]; render( @@ -1470,6 +3992,9 @@ describe('Testing Create Direct Chat Modal [User Portal]', () => { ...CHATS_LIST_MOCK, ...CHAT_BY_ID_QUERY_MOCK, ...CREATE_CHAT_MUTATION_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ...UNREAD_CHAT_LIST_QUERY_MOCK, + ...GROUP_CHAT_BY_USER_ID_QUERY_MOCK, ]; render( diff --git a/src/components/UserPortal/CreateDirectChat/CreateDirectChat.tsx b/src/components/UserPortal/CreateDirectChat/CreateDirectChat.tsx index 24c853fcdd..8125b6a463 100644 --- a/src/components/UserPortal/CreateDirectChat/CreateDirectChat.tsx +++ b/src/components/UserPortal/CreateDirectChat/CreateDirectChat.tsx @@ -17,6 +17,7 @@ import { USERS_CONNECTION_LIST } from 'GraphQl/Queries/Queries'; import Loader from 'components/Loader/Loader'; import { Search } from '@mui/icons-material'; import { useParams } from 'react-router-dom'; +import { useTranslation } from 'react-i18next'; interface InterfaceCreateDirectChatProps { toggleCreateDirectChatModal: () => void; @@ -27,7 +28,7 @@ interface InterfaceCreateDirectChatProps { id: string; }> | undefined, - ) => Promise>; + ) => Promise>; } /** @@ -61,6 +62,9 @@ export default function createDirectChatModal({ createDirectChatModalisOpen, chatsListRefetch, }: InterfaceCreateDirectChatProps): JSX.Element { + const { t } = useTranslation('translation', { + keyPrefix: 'userChat', + }); const { orgId: organizationId } = useParams(); const userId: string | null = getItem('userId'); @@ -187,7 +191,7 @@ export default function createDirectChatModal({ }} data-testid="addBtn" > - Add + {t('add')} diff --git a/src/components/UserPortal/CreateGroupChat/CreateGroupChat.module.css b/src/components/UserPortal/CreateGroupChat/CreateGroupChat.module.css index 3795e402fa..77fcfaf38f 100644 --- a/src/components/UserPortal/CreateGroupChat/CreateGroupChat.module.css +++ b/src/components/UserPortal/CreateGroupChat/CreateGroupChat.module.css @@ -7,3 +7,32 @@ .modalContent { width: 530px; } + +.groupInfo { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; +} + +.groupImage { + margin-bottom: 10px; +} + +.editImgBtn { + padding: 2px 6px 6px 8px; + border-radius: 100%; + background-color: white; + border: 1px solid #959595; + color: #959595; + outline: none; + position: relative; + top: -40px; + left: 40px; +} + +.chatImage { + height: 120px; + border-radius: 100%; + width: 120px; +} diff --git a/src/components/UserPortal/CreateGroupChat/CreateGroupChat.spec.tsx b/src/components/UserPortal/CreateGroupChat/CreateGroupChat.spec.tsx index 711bb29a93..440273cbc4 100644 --- a/src/components/UserPortal/CreateGroupChat/CreateGroupChat.spec.tsx +++ b/src/components/UserPortal/CreateGroupChat/CreateGroupChat.spec.tsx @@ -5,7 +5,6 @@ import { render, screen, waitFor, - within, } from '@testing-library/react'; import { MockedProvider } from '@apollo/react-testing'; import { I18nextProvider } from 'react-i18next'; @@ -21,11 +20,16 @@ import i18nForTest from 'utils/i18nForTest'; import Chat from '../../../screens/UserPortal/Chat/Chat'; import { CREATE_CHAT, + MARK_CHAT_MESSAGES_AS_READ, MESSAGE_SENT_TO_CHAT, } from 'GraphQl/Mutations/OrganizationMutations'; -import { CHATS_LIST, CHAT_BY_ID } from 'GraphQl/Queries/PlugInQueries'; +import { + CHATS_LIST, + CHAT_BY_ID, + GROUP_CHAT_LIST, + UNREAD_CHAT_LIST, +} from 'GraphQl/Queries/PlugInQueries'; import useLocalStorage from 'utils/useLocalstorage'; -import userEvent from '@testing-library/user-event'; import { vi } from 'vitest'; /** @@ -1228,6 +1232,9 @@ const MESSAGE_SENT_TO_CHAT_MOCK = [ data: { messageSentToChat: { _id: '668ec1f1364e03ac47a151', + chatMessageBelongsTo: { + _id: '1', + }, createdAt: '2024-07-10T17:16:33.248Z', messageContent: 'Test ', type: 'STRING', @@ -1254,6 +1261,9 @@ const MESSAGE_SENT_TO_CHAT_MOCK = [ data: { messageSentToChat: { _id: '668ec1f1df364e03ac47a151', + chatMessageBelongsTo: { + _id: '1', + }, createdAt: '2024-07-10T17:16:33.248Z', messageContent: 'Test ', replyTo: null, @@ -1280,6 +1290,9 @@ const MESSAGE_SENT_TO_CHAT_MOCK = [ data: { messageSentToChat: { _id: '668ec1f13603ac4697a151', + chatMessageBelongsTo: { + _id: '1', + }, createdAt: '2024-07-10T17:16:33.248Z', messageContent: 'Test ', replyTo: null, @@ -1328,6 +1341,7 @@ const CHAT_BY_ID_QUERY_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1354,6 +1368,19 @@ const CHAT_BY_ID_QUERY_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + }), }, }, }, @@ -1388,6 +1415,7 @@ const CHAT_BY_ID_QUERY_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1414,6 +1442,19 @@ const CHAT_BY_ID_QUERY_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + }), }, }, }, @@ -1448,6 +1489,7 @@ const CHAT_BY_ID_QUERY_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1474,26 +1516,40 @@ const CHAT_BY_ID_QUERY_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + }), }, }, }, }, ]; -const CHATS_LIST_MOCK = [ +const UNREAD_CHAT_BY_USER_ID_QUERY_MOCK = [ { request: { - query: CHATS_LIST, + query: UNREAD_CHAT_LIST, variables: { id: null, }, }, result: { data: { - chatsByUserId: [ + getUnreadChatsByUserId: [ { - _id: '65844efc814dd40fgh03db811c4', + _id: '65844efc814dd40hgjfgh03db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1515,6 +1571,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1562,10 +1619,33 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getUnreadChatsByUserId: [ { - _id: '65844efc814ddgh4003db811c4', + _id: '65844efc814dd40hgjfgh03db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1587,6 +1667,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1634,6 +1715,14 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, ], }, @@ -1641,17 +1730,18 @@ const CHATS_LIST_MOCK = [ }, { request: { - query: CHATS_LIST, + query: UNREAD_CHAT_LIST, variables: { - id: '', + id: null, }, }, result: { data: { - chatsByUserId: [ + getUnreadChatsByUserId: [ { - _id: '65844ghjefc814dd4003db811c4', + _id: '65844efc814dd40hgjfgh03db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1673,6 +1763,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1720,10 +1811,33 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getUnreadChatsByUserId: [ { - _id: 'ujhgtrdtyuiop', + _id: '65844efc814dd40hgjfgh03db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1745,6 +1859,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1792,6 +1907,14 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, ], }, @@ -1799,17 +1922,18 @@ const CHATS_LIST_MOCK = [ }, { request: { - query: CHATS_LIST, + query: UNREAD_CHAT_LIST, variables: { - id: '1', + id: null, }, }, result: { data: { - chatsByUserId: [ + getUnreadChatsByUserId: [ { - _id: '65844efc814dhjmkdftyd4003db811c4', + _id: '65844efc814dd40hgjfgh03db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1831,6 +1955,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1878,10 +2003,33 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + getUnreadChatsByUserId: [ { - _id: '65844ewsedrffc814dd4003db811c4', + _id: '65844efc814dd40hgjfgh03db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1903,6 +2051,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1950,138 +2099,3235 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, ], }, }, }, -]; - -const GROUP_CHAT_BY_ID_QUERY_MOCK = [ { request: { - query: CHAT_BY_ID, + query: UNREAD_CHAT_LIST, variables: { - id: '', + id: '1', }, }, result: { data: { - chatById: { - _id: '65844efc814dd4003db811c4', - isGroup: true, - creator: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', + getUnreadChatsByUserId: [ + { + _id: '65844efc814dd40hgjfgh03db811c4', + isGroup: true, image: null, - email: 'testsuperadmin@example.com', - createdAt: '2023-04-13T04:53:17.742Z', - __typename: 'User', - }, - organization: { - _id: 'pw3ertyuiophgfre45678', - name: 'rtyu', - }, - createdAt: '2345678903456', - name: 'Test Group Chat', - messages: [ - { - _id: '345678', - createdAt: '345678908765', - messageContent: 'Hello', - replyTo: null, - type: 'STRING', - sender: { + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { _id: '2', firstName: 'Test', lastName: 'User', email: 'test@example.com', image: '', }, - }, - ], - users: [ - { - _id: '1', - firstName: 'Disha', - lastName: 'Talreja', - email: 'disha@example.com', - image: '', - }, - { - _id: '2', - firstName: 'Test', - lastName: 'User', - email: 'test@example.com', - image: '', - }, - { - _id: '3', - firstName: 'Test', - lastName: 'User1', - email: 'test1@example.com', - image: '', - }, - { - _id: '4', - firstName: 'Test', - lastName: 'User2', - email: 'test2@example.com', - image: '', - }, - { - _id: '5', - firstName: 'Test', - lastName: 'User4', - email: 'test4@example.com', - image: '', - }, - ], - }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], }, }, }, -]; - -const CREATE_CHAT_MUTATION = [ { request: { - query: CREATE_CHAT, + query: UNREAD_CHAT_LIST, variables: { - organizationId: '6401ff65ce8e8406b8jygjgf07af2', - userIds: [null], - name: 'Test Group', - isGroup: true, + id: '1', }, }, result: { data: { - createChat: { - _id: '65844efc814dd4003db811c4', - isGroup: true, - creator: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', + getUnreadChatsByUserId: [ + { + _id: '65844efc814dd40hgjfgh03db811c4', + isGroup: true, image: null, - email: 'testsuperadmin@example.com', - createdAt: '2023-04-13T04:53:17.742Z', - __typename: 'User', - }, - organization: { - _id: 'pw3ertyuiophgfre45678', - name: 'rtyu', - }, - createdAt: '2345678903456', - name: 'Test Group Chat', - messages: [ - { - _id: '345678', - createdAt: '345678908765', - messageContent: 'Hello', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '65844efc814dd40hgjfgh03db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '65844efc814dd40hgjfgh03db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '65844efc814dd40hgjfgh03db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '65844efc814dd40hgjfgh03db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, +]; + +const CHATS_LIST_MOCK = [ + { + request: { + query: CHATS_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40hgjfgh03db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844ghjefc814dd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: 'fcfgcgchnbjhgfrftghj', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40fgh03db8gjhbhn11c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844ghjefc814dd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: 'ujhgtrdtyuiop', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dhjmkdftyd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844ewsedrffc814dd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, +]; + +const GROUP_CHAT_LIST_QUERY_MOCK = [ + { + request: { + query: GROUP_CHAT_LIST, + variables: { + id: '', + }, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, +]; + +const GROUP_CHAT_BY_ID_QUERY_MOCK = [ + { + request: { + query: CHAT_BY_ID, + variables: { + id: '', + }, + }, + result: { + data: { + chatById: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, +]; + +const CREATE_CHAT_MUTATION = [ + { + request: { + query: CREATE_CHAT, + variables: { + organizationId: '6401ff65ce8e8406b8jygjgf07af2', + userIds: [null], + name: 'Test Group', + isGroup: true, + image: null, + }, + }, + result: { + data: { + createChat: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: CREATE_CHAT, + variables: { + organizationId: '6401ff65ce8e8406b8jygjgf07af2', + userIds: [null], + name: 'Test Group', + isGroup: true, + image: null, + }, + }, + result: { + data: { + createChat: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: CREATE_CHAT, + variables: { + organizationId: '6401ff65ce8e8406b8jygjgf07af2', + userIds: [null], + name: 'Test Group', + isGroup: true, + image: null, + }, + }, + result: { + data: { + createChat: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: CREATE_CHAT, + variables: { + organizationId: '6401ff65ce8e8406b8jygjgf07af2', + userIds: [null], + name: 'Test Group', + isGroup: true, + image: null, + }, + }, + result: { + data: { + createChat: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: CREATE_CHAT, + variables: { + userIds: [null], + name: 'Test Group', + isGroup: true, + image: null, + }, + }, + result: { + data: { + createChat: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: CREATE_CHAT, + variables: { + userIds: [null], + name: 'Test Group', + isGroup: true, + image: null, + }, + }, + result: { + data: { + createChat: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: CREATE_CHAT, + variables: { + userIds: [null], + name: 'Test Group', + isGroup: true, + image: null, + }, + }, + result: { + data: { + createChat: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: CREATE_CHAT, + variables: { + userIds: [null], + name: 'Test Group', + isGroup: true, + image: null, + }, + }, + result: { + data: { + createChat: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', replyTo: null, type: 'STRING', + media: null, sender: { _id: '2', firstName: 'Test', @@ -2128,6 +5374,14 @@ const CREATE_CHAT_MUTATION = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, }, }, @@ -2140,6 +5394,7 @@ const CREATE_CHAT_MUTATION = [ userIds: [null], name: 'Test Group', isGroup: true, + image: null, }, }, result: { @@ -2147,6 +5402,7 @@ const CREATE_CHAT_MUTATION = [ createChat: { _id: '65844efc814dd4003db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -2168,6 +5424,7 @@ const CREATE_CHAT_MUTATION = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -2215,6 +5472,97 @@ const CREATE_CHAT_MUTATION = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, +]; + +const MARK_CHAT_MESSAGES_AS_READ_MOCK = [ + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: null, + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: null, + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '1', + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '1', + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '1', + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', }, }, }, @@ -2256,6 +5604,9 @@ describe('Testing Create Group Chat Modal [User Portal]', () => { ...UserConnectionListMock, ...CREATE_CHAT_MUTATION, ...CHATS_LIST_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ...UNREAD_CHAT_BY_USER_ID_QUERY_MOCK, + ...GROUP_CHAT_LIST_QUERY_MOCK, ]; render( @@ -2274,7 +5625,7 @@ describe('Testing Create Group Chat Modal [User Portal]', () => { const dropdown = await screen.findByTestId('dropdown'); expect(dropdown).toBeInTheDocument(); fireEvent.click(dropdown); - const newGroupChatBtn = await screen.findByTestId('newGroupChat'); + const newGroupChatBtn = await screen.findByTestId('newDirectChat'); expect(newGroupChatBtn).toBeInTheDocument(); fireEvent.click(newGroupChatBtn); @@ -2294,6 +5645,9 @@ describe('Testing Create Group Chat Modal [User Portal]', () => { ...UserConnectionListMock, ...CREATE_CHAT_MUTATION, ...CHATS_LIST_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ...UNREAD_CHAT_BY_USER_ID_QUERY_MOCK, + ...GROUP_CHAT_LIST_QUERY_MOCK, ]; render( @@ -2324,9 +5678,9 @@ describe('Testing Create Group Chat Modal [User Portal]', () => { ).toBeInTheDocument(); }); - const groupTitleInput = screen.getByLabelText( - 'Group name', - ) as HTMLInputElement; + const groupTitleInput = (await screen.findByTestId( + 'groupTitleInput', + )) as unknown as HTMLInputElement; expect(groupTitleInput).toBeInTheDocument(); @@ -2335,35 +5689,6 @@ describe('Testing Create Group Chat Modal [User Portal]', () => { expect(groupTitleInput.value).toBe('Test Group'); }); - const selectLabel = /select organization/i; - const orgSelect = await screen.findByLabelText('Select Organization'); - // console.log(prettyDOM(document)); - - // act(() => { - // fireEvent.change(orgSelect, { - // target: { value: '6401ff65ce8e8406b8f07af2' }, - // }); - // }) - // fireEvent.change(orgSelect, { - // target: { value: '6401ff65ce8e8406b8f07af2' }, - // }); - - // act(() => { - userEvent.click(orgSelect); - - const optionsPopupEl = await screen.findByRole('listbox', { - name: selectLabel, - }); - - userEvent.click(within(optionsPopupEl).getByText(/any organization/i)); - // }); - - // await waitFor(async () => { - // const option = await screen.findAllByText('Any Organization'); - - // console.log("option", option); - // }); - const nextBtn = await screen.findByTestId('nextBtn'); act(() => { @@ -2379,9 +5704,9 @@ describe('Testing Create Group Chat Modal [User Portal]', () => { fireEvent.click(await screen.findByTestId('createBtn')); }); - // await waitFor(() => { - // expect(createBtn).not.toBeInTheDocument(); - // }); + await waitFor(() => { + expect(createBtn).not.toBeInTheDocument(); + }); }, 3000); it('add and remove user', async () => { @@ -2395,6 +5720,9 @@ describe('Testing Create Group Chat Modal [User Portal]', () => { ...UserConnectionListMock, ...CREATE_CHAT_MUTATION, ...CHATS_LIST_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ...UNREAD_CHAT_BY_USER_ID_QUERY_MOCK, + ...GROUP_CHAT_LIST_QUERY_MOCK, ]; render( diff --git a/src/components/UserPortal/CreateGroupChat/CreateGroupChat.tsx b/src/components/UserPortal/CreateGroupChat/CreateGroupChat.tsx index e293675a03..f61dcf620d 100644 --- a/src/components/UserPortal/CreateGroupChat/CreateGroupChat.tsx +++ b/src/components/UserPortal/CreateGroupChat/CreateGroupChat.tsx @@ -1,18 +1,9 @@ -import { - FormControl, - InputLabel, - MenuItem, - Paper, - Select, - TableBody, -} from '@mui/material'; -import type { SelectChangeEvent } from '@mui/material/Select'; -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; +import { Paper, TableBody } from '@mui/material'; import { Button, Form, Modal } from 'react-bootstrap'; import styles from './CreateGroupChat.module.css'; import type { ApolloQueryResult } from '@apollo/client'; import { useMutation, useQuery } from '@apollo/client'; -import { USER_JOINED_ORGANIZATIONS } from 'GraphQl/Queries/OrganizationQueries'; import useLocalStorage from 'utils/useLocalstorage'; import { CREATE_CHAT } from 'GraphQl/Mutations/OrganizationMutations'; import Table from '@mui/material/Table'; @@ -25,6 +16,11 @@ import type { InterfaceQueryUserListItem } from 'utils/interfaces'; import { USERS_CONNECTION_LIST } from 'GraphQl/Queries/Queries'; import Loader from 'components/Loader/Loader'; import { Search } from '@mui/icons-material'; +import { useTranslation } from 'react-i18next'; +import { useParams } from 'react-router-dom'; +import convertToBase64 from 'utils/convertToBase64'; +import Avatar from 'components/Avatar/Avatar'; +import { FiEdit } from 'react-icons/fi'; interface InterfaceCreateGroupChatProps { toggleCreateGroupChatModal: () => void; @@ -35,31 +31,7 @@ interface InterfaceCreateGroupChatProps { id: string; }> | undefined, - ) => Promise>; -} - -interface InterfaceOrganization { - _id: string; - name: string; - image: string; - description: string; - admins: []; - members: []; - address: { - city: string; - countryCode: string; - line1: string; - postalCode: string; - state: string; - }; - membershipRequestStatus: string; - userRegistrationRequired: boolean; - membershipRequests: { - _id: string; - user: { - _id: string; - }; - }[]; + ) => Promise>; } /** @@ -94,12 +66,14 @@ export default function CreateGroupChat({ chatsListRefetch, }: InterfaceCreateGroupChatProps): JSX.Element { const userId: string | null = getItem('userId'); + const { t } = useTranslation('translation', { + keyPrefix: 'userChat', + }); const [createChat] = useMutation(CREATE_CHAT); - const [organizations, setOrganizations] = useState([]); - const [selectedOrganization, setSelectedOrganization] = useState(''); const [title, setTitle] = useState(''); + const [description, setDescription] = useState(''); const [userIds, setUserIds] = useState([]); const [addUserModalisOpen, setAddUserModalisOpen] = useState(false); @@ -111,21 +85,11 @@ export default function CreateGroupChat({ const toggleAddUserModal = /* istanbul ignore next */ (): void => setAddUserModalisOpen(!addUserModalisOpen); - const handleChange = (event: SelectChangeEvent): void => { - setSelectedOrganization(event.target.value as string); - }; - - const { data: joinedOrganizationsData } = useQuery( - USER_JOINED_ORGANIZATIONS, - { - variables: { id: userId }, - }, - ); + const { orgId: currentOrg } = useParams(); function reset(): void { setTitle(''); setUserIds([]); - setSelectedOrganization(''); } useEffect(() => { @@ -135,10 +99,11 @@ export default function CreateGroupChat({ async function handleCreateGroupChat(): Promise { await createChat({ variables: { - organizationId: selectedOrganization, + organizationId: currentOrg, userIds: [userId, ...userIds], name: title, isGroup: true, + image: selectedImage, }, }); chatsListRefetch(); @@ -175,13 +140,23 @@ export default function CreateGroupChat({ }); }; - useEffect(() => { - if (joinedOrganizationsData && joinedOrganizationsData.users.length > 0) { - const organizations = - joinedOrganizationsData.users[0]?.user?.joinedOrganizations || []; - setOrganizations(organizations); + const [selectedImage, setSelectedImage] = useState(null); + + const fileInputRef = useRef(null); + + const handleImageClick = (): void => { + fileInputRef?.current?.click(); + }; + + const handleImageChange = async ( + e: React.ChangeEvent, + ): Promise => { + const file = e.target.files?.[0]; + if (file) { + const base64 = await convertToBase64(file); + setSelectedImage(base64); } - }, [joinedOrganizationsData]); + }; return ( <> @@ -195,44 +170,57 @@ export default function CreateGroupChat({ New Group + +
+ {selectedImage ? ( + + ) : ( + + )} + +
- - Select Organization - - - Group name + Title { setTitle(e.target.value); }} /> + + Description + { + setDescription(e.target.value); + }} + /> + )} @@ -358,7 +346,7 @@ export default function CreateGroupChat({ onClick={handleCreateGroupChat} data-testid="createBtn" > - Create + {t('create')} diff --git a/src/components/UserPortal/UserSidebar/UserSidebar.spec.tsx b/src/components/UserPortal/UserSidebar/UserSidebar.spec.tsx index ac6465a3e6..6435353f89 100644 --- a/src/components/UserPortal/UserSidebar/UserSidebar.spec.tsx +++ b/src/components/UserPortal/UserSidebar/UserSidebar.spec.tsx @@ -426,7 +426,7 @@ describe('UserSidebar Component Tests in User Portal', () => { await wait(); }); - const expectedLinks = ['My Organizations', 'Settings', 'Chat']; + const expectedLinks = ['My Organizations', 'Settings']; expectedLinks.forEach((link) => { expect(screen.getByText(link)).toBeInTheDocument(); }); @@ -483,8 +483,8 @@ describe('UserSidebar Component Tests in User Portal', () => { renderUserSidebar('properId', link); await wait(); }); - const chatBtn = screen.getByTestId('chatBtn'); - fireEvent.click(chatBtn); + const settingsBtn = screen.getByTestId('settingsBtn'); + fireEvent.click(settingsBtn); expect(props.setHideDrawer).toHaveBeenCalledWith(true); }); diff --git a/src/components/UserPortal/UserSidebar/UserSidebar.tsx b/src/components/UserPortal/UserSidebar/UserSidebar.tsx index 5e258f8a8e..010d8d0e52 100644 --- a/src/components/UserPortal/UserSidebar/UserSidebar.tsx +++ b/src/components/UserPortal/UserSidebar/UserSidebar.tsx @@ -4,7 +4,6 @@ import { useTranslation } from 'react-i18next'; import { NavLink } from 'react-router-dom'; import OrganizationsIcon from 'assets/svgs/organizations.svg?react'; import SettingsIcon from 'assets/svgs/settings.svg?react'; -import ChatIcon from 'assets/svgs/chat.svg?react'; import TalawaLogo from 'assets/svgs/talawa.svg?react'; import styles from './UserSidebar.module.css'; @@ -109,28 +108,6 @@ const userSidebar = ({ )} - - {({ isActive }) => ( - - )} -
diff --git a/src/screens/OrganizationEvents/OrganizationEvents.tsx b/src/screens/OrganizationEvents/OrganizationEvents.tsx index 12abb3e74a..71295c1dc9 100644 --- a/src/screens/OrganizationEvents/OrganizationEvents.tsx +++ b/src/screens/OrganizationEvents/OrganizationEvents.tsx @@ -71,6 +71,7 @@ function organizationEvents(): JSX.Element { const [publicchecked, setPublicChecked] = React.useState(true); const [registrablechecked, setRegistrableChecked] = React.useState(false); + const [createChatCheck, setCreateChatCheck] = React.useState(false); const [recurrenceRuleState, setRecurrenceRuleState] = useState({ @@ -476,6 +477,19 @@ function organizationEvents(): JSX.Element { /> +
+
+ + setCreateChatCheck(!createChatCheck)} + /> +
+
{/* Recurrence Options */} {recurringchecked && ( diff --git a/src/screens/UserPortal/Chat/Chat.module.css b/src/screens/UserPortal/Chat/Chat.module.css index 5f9a672dea..aeab28f66c 100644 --- a/src/screens/UserPortal/Chat/Chat.module.css +++ b/src/screens/UserPortal/Chat/Chat.module.css @@ -1,6 +1,6 @@ .containerHeight { - padding: 1rem 1.5rem 0 calc(300px); - height: 100vh; + /* padding: 1rem 1.5rem 0 calc(300px); */ + /* height: 100vh; */ } .expand { @@ -32,7 +32,7 @@ } .containerHeight { - height: 100vh; + height: 88vh; } .mainContainer { @@ -188,8 +188,8 @@ /* For tablets */ @media (max-width: 820px) { .containerHeight { - height: 100vh; - padding: 2rem; + /* height: 100vh; */ + /* padding: 2rem; */ } .contract, @@ -216,3 +216,25 @@ .accordionBody::-webkit-scrollbar { display: none; } + +.filters { + padding: 20px 0px 0px 20px; + display: flex; + gap: 8px; +} + +.filterButton { + border-radius: 14px; + padding: 5px 10px; + background-color: white; + color: #a5a5a5; + border: none; + border: 1px solid #a5a5a5; +} + +.selectedBtn, +.filterButton:hover { + border: 1px solid #98e0b6; + background-color: #98e0b6; + color: rgb(255, 255, 255); +} diff --git a/src/screens/UserPortal/Chat/Chat.spec.tsx b/src/screens/UserPortal/Chat/Chat.spec.tsx index ec8243c823..e691e4151d 100644 --- a/src/screens/UserPortal/Chat/Chat.spec.tsx +++ b/src/screens/UserPortal/Chat/Chat.spec.tsx @@ -1,10 +1,10 @@ import React from 'react'; import { - render, + act, fireEvent, + render, screen, waitFor, - act, } from '@testing-library/react'; import { MockedProvider } from '@apollo/react-testing'; import { BrowserRouter } from 'react-router-dom'; @@ -18,8 +18,16 @@ import { USERS_CONNECTION_LIST, USER_JOINED_ORGANIZATIONS, } from 'GraphQl/Queries/Queries'; -import { MESSAGE_SENT_TO_CHAT } from 'GraphQl/Mutations/OrganizationMutations'; -import { CHATS_LIST, CHAT_BY_ID } from 'GraphQl/Queries/PlugInQueries'; +import { + MARK_CHAT_MESSAGES_AS_READ, + MESSAGE_SENT_TO_CHAT, +} from 'GraphQl/Mutations/OrganizationMutations'; +import { + CHATS_LIST, + CHAT_BY_ID, + GROUP_CHAT_LIST, + UNREAD_CHAT_LIST, +} from 'GraphQl/Queries/PlugInQueries'; import useLocalStorage from 'utils/useLocalstorage'; /** @@ -38,11 +46,6 @@ vi.mock('../../../components/UserPortal/ChatRoom/ChatRoom', () => ({ default: () =>
Mocked ChatRoom
, })); -const resizeWindow = (width: number): void => { - window.innerWidth = width; - fireEvent(window, new Event('resize')); -}; - async function wait(ms = 100): Promise { await act(() => { return new Promise((resolve) => { @@ -52,6 +55,89 @@ async function wait(ms = 100): Promise { } const { setItem } = useLocalStorage(); +const MARK_CHAT_MESSAGES_AS_READ_MOCK = [ + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: null, + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: null, + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '1', + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '1', + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '1', + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, +]; + const USER_JOINED_ORG_MOCK = [ { request: { @@ -828,6 +914,11 @@ const CHAT_BY_ID_QUERY_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + }), }, }, }, @@ -879,34 +970,71 @@ const CHAT_BY_ID_QUERY_MOCK = [ lastName: 'Talreja', email: 'disha@example.com', image: '', - appUserProfile: { - _id: '64378abd85308f171cf2993d', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - __typename: 'AppUserProfile', - }, - __typename: 'UserData', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + }), }, }, }, }, { request: { - query: USERS_CONNECTION_LIST, + query: CHAT_BY_ID, variables: { - firstName_contains: '', - lastName_contains: '', + id: '', }, }, result: { data: { - users: { - user: [ + chatById: { + _id: '1', + isGroup: false, + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + createdAt: '2345678903456', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, { _id: '2', firstName: 'Test', @@ -915,6 +1043,7 @@ const CHAT_BY_ID_QUERY_MOCK = [ image: '', }, ], + admins: [], }, }, }, @@ -933,7 +1062,8 @@ const CHATS_LIST_MOCK = [ data: { chatsByUserId: [ { - _id: '65844efc814dd40fgh03db811c4', + _id: '65844efc814dd40sassxaasfgh03db811c4', + image: '', isGroup: true, creator: { _id: '64378abd85008f171cf2990d', @@ -1003,10 +1133,27 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, { - _id: '65844efc814ddgh4003db811c4', + _id: '65844efc8q14ddgh4003db811c4', isGroup: true, + image: '', creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1075,6 +1222,14 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, ], }, @@ -1091,8 +1246,9 @@ const CHATS_LIST_MOCK = [ data: { chatsByUserId: [ { - _id: '65844ghjefc814dd4003db811c4', + _id: '65844efc814dd40fgh03db811c4', isGroup: true, + image: '', creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1161,10 +1317,27 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, { - _id: 'ujhgtrdtyuiop', + _id: '65844efc814ddgh4003db811c4', isGroup: true, + image: '', creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1233,6 +1406,14 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, ], }, @@ -1242,15 +1423,16 @@ const CHATS_LIST_MOCK = [ request: { query: CHATS_LIST, variables: { - id: '1', + id: null, }, }, result: { data: { chatsByUserId: [ { - _id: '65844efc814dhjmkdftyd4003db811c4', + _id: '65844efc814dd40fggfdh03db811c4', isGroup: true, + image: '', creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1319,10 +1501,27 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, { - _id: '65844ewsedrffc814dd4003db811c4', + _id: '65844efc814ddgh4003db811c4', isGroup: true, + image: '', creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1391,95 +1590,2652 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, ], }, }, }, -]; - -const GROUP_CHAT_BY_ID_QUERY_MOCK = [ { request: { - query: CHAT_BY_ID, + query: CHATS_LIST, variables: { - id: '', + id: null, }, }, result: { data: { - chatById: { - _id: '65844efc814dd4003db811c4', - isGroup: true, - creator: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', - image: null, - email: 'testsuperadmin@example.com', - createdAt: '2023-04-13T04:53:17.742Z', - __typename: 'User', - }, - organization: { - _id: 'pw3ertyuiophgfre45678', - name: 'rtyu', - }, - createdAt: '2345678903456', - name: 'Test Group Chat', - messages: [ - { - _id: '345678', - createdAt: '345678908765', - messageContent: 'Hello', - replyTo: null, - type: 'STRING', - sender: { + chatsByUserId: [ + { + _id: '65844efc814dd40wasxfgh03db811c4', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { _id: '2', firstName: 'Test', lastName: 'User', email: 'test@example.com', image: '', }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844ghjefc814dd4003db811c4', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: 'ujhgtrdtyuiop', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dhjmkdftyd4003db811c4', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844ewsedrffc814dd4003db811c4', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dhjmkdftyd4003db811c4', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844ewsedrffc814dd4003db811c4', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dhjmkdftyd4003db811c4', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844ewsedrffc814dd4003db811c4', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dhjmkdftyd4003db811c4', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844ewsedrffc814dd4003db811c4', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, +]; + +const GROUP_CHAT_BY_ID_QUERY_MOCK = [ + { + request: { + query: CHAT_BY_ID, + variables: { + id: '', + }, + }, + result: { + data: { + chatById: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, +]; + +const UNREAD_CHAT_LIST_QUERY_MOCK = [ + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: null, + name: '', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + ], + }, + }, + }, +]; + +const GROUP_CHAT_LIST_QUERY_MOCK = [ + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: [ + { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: [ + { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + type: 'STRING', + media: null, + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: [ + { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: [ + { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', }, - ], - users: [ - { - _id: '1', - firstName: 'Disha', - lastName: 'Talreja', - email: 'disha@example.com', - image: '', - }, - { - _id: '2', - firstName: 'Test', - lastName: 'User', - email: 'test@example.com', - image: '', + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + type: 'STRING', + media: null, + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: [ + { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + type: 'STRING', + media: null, + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: [ + { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', + }, + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: [ + { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', }, - { - _id: '3', - firstName: 'Test', - lastName: 'User1', - email: 'test1@example.com', - image: '', + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', }, - { - _id: '4', - firstName: 'Test', - lastName: 'User2', - email: 'test2@example.com', - image: '', + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: [ + { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', }, - { - _id: '5', - firstName: 'Test', - lastName: 'User4', - email: 'test4@example.com', - image: '', + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', }, - ], - }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + { + _id: '3', + firstName: 'Test', + lastName: 'User1', + email: 'test1@example.com', + image: '', + }, + { + _id: '4', + firstName: 'Test', + lastName: 'User2', + email: 'test2@example.com', + image: '', + }, + { + _id: '5', + firstName: 'Test', + lastName: 'User4', + email: 'test4@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], }, }, }, @@ -1500,18 +4256,6 @@ describe('Testing Chat Screen [User Portal]', () => { })), }); - // Define mock data outside of tests to reuse - const mock = [ - ...USER_JOINED_ORG_MOCK, - ...GROUP_CHAT_BY_ID_QUERY_MOCK, - ...MESSAGE_SENT_TO_CHAT_MOCK, - ...MESSAGE_SENT_TO_CHAT_MOCK, - ...UserConnectionListMock, - ...CHAT_BY_ID_QUERY_MOCK, - ...CHATS_LIST_MOCK, - ...UserConnectionListMock, - ]; - beforeEach(() => { setItem('userId', '1'); vi.clearAllMocks(); @@ -1523,6 +4267,20 @@ describe('Testing Chat Screen [User Portal]', () => { localStorage.clear(); }); + const mock = [ + ...USER_JOINED_ORG_MOCK, + ...GROUP_CHAT_BY_ID_QUERY_MOCK, + ...MESSAGE_SENT_TO_CHAT_MOCK, + ...MESSAGE_SENT_TO_CHAT_MOCK, + ...UserConnectionListMock, + ...CHAT_BY_ID_QUERY_MOCK, + ...CHATS_LIST_MOCK, + ...UserConnectionListMock, + ...UNREAD_CHAT_LIST_QUERY_MOCK, + ...GROUP_CHAT_LIST_QUERY_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ]; + test('Screen should be rendered properly', async () => { render( @@ -1538,7 +4296,7 @@ describe('Testing Chat Screen [User Portal]', () => { await wait(); }); - it('User is able to select a contact', async () => { + test('User is able to select a contact', async () => { render( @@ -1616,11 +4374,13 @@ describe('Testing Chat Screen [User Portal]', () => { const closeButton = screen.getByRole('button', { name: /close/i }); expect(closeButton).toBeInTheDocument(); - fireEvent.click(closeButton); }); - test('sidebar', async () => { + // filter chat test + test('Testing chat filters', async () => { + setItem('userId', '1'); + render( @@ -1632,44 +4392,23 @@ describe('Testing Chat Screen [User Portal]', () => { , ); - screen.debug(); await waitFor(async () => { - const closeMenuBtn = await screen.findByTestId('closeMenu'); - expect(closeMenuBtn).toBeInTheDocument(); - if (closeMenuBtn) { - closeMenuBtn.click(); - } else { - throw new Error('Close menu button not found'); - } + expect(await screen.findByTestId('unreadChat')).toBeInTheDocument(); + }); + await act(async () => { + fireEvent.click(await screen.findByTestId('unreadChat')); }); - }); - - test('Testing sidebar when the screen size is less than or equal to 820px', async () => { - // Resize window for mobile view (<= 820px) - resizeWindow(800); - render( - - - - - - - - - , - ); + await wait(1000); - await waitFor(() => { - expect(screen.getByText('My Organizations')).toBeInTheDocument(); - expect(screen.getByText('Talawa User Portal')).toBeInTheDocument(); + await act(async () => { + fireEvent.click(await screen.findByTestId('groupChat')); }); - const openMenuBtn = await screen.findByTestId('openMenu'); - expect(openMenuBtn).toBeInTheDocument(); - fireEvent.click(openMenuBtn); + await wait(1000); - const closeMenuBtn = await screen.findByTestId('closeMenu'); - expect(closeMenuBtn).toBeInTheDocument(); + await act(async () => { + fireEvent.click(await screen.findByTestId('allChat')); + }); }); }); diff --git a/src/screens/UserPortal/Chat/Chat.tsx b/src/screens/UserPortal/Chat/Chat.tsx index 441ce7d4ba..0155f3ee0a 100644 --- a/src/screens/UserPortal/Chat/Chat.tsx +++ b/src/screens/UserPortal/Chat/Chat.tsx @@ -1,18 +1,21 @@ import React, { useEffect, useState } from 'react'; -import { useQuery } from '@apollo/client'; +import { useMutation, useQuery } from '@apollo/client'; import { useTranslation } from 'react-i18next'; import { Button, Dropdown } from 'react-bootstrap'; -import { SearchOutlined, Search } from '@mui/icons-material'; import HourglassBottomIcon from '@mui/icons-material/HourglassBottom'; import ContactCard from 'components/UserPortal/ContactCard/ContactCard'; import ChatRoom from 'components/UserPortal/ChatRoom/ChatRoom'; import useLocalStorage from 'utils/useLocalstorage'; import NewChat from 'assets/svgs/newChat.svg?react'; import styles from './Chat.module.css'; -import UserSidebar from 'components/UserPortal/UserSidebar/UserSidebar'; -import { CHATS_LIST } from 'GraphQl/Queries/PlugInQueries'; +import { + CHATS_LIST, + GROUP_CHAT_LIST, + UNREAD_CHAT_LIST, +} from 'GraphQl/Queries/PlugInQueries'; import CreateGroupChat from '../../../components/UserPortal/CreateGroupChat/CreateGroupChat'; import CreateDirectChat from 'components/UserPortal/CreateDirectChat/CreateDirectChat'; +import { MARK_CHAT_MESSAGES_AS_READ } from 'GraphQl/Mutations/OrganizationMutations'; interface InterfaceContactCardProps { id: string; @@ -21,6 +24,8 @@ interface InterfaceContactCardProps { selectedContact: string; setSelectedContact: React.Dispatch>; isGroup: boolean; + unseenMessages: number; + lastMessage: string; } /** * The `chat` component provides a user interface for interacting with contacts and chat rooms within an organization. @@ -48,15 +53,62 @@ interface InterfaceContactCardProps { * * @returns The rendered `chat` component. */ + +type DirectMessage = { + _id: string; + createdAt: Date; + sender: { + _id: string; + firstName: string; + lastName: string; + image: string; + }; + replyTo: + | { + _id: string; + createdAt: Date; + sender: { + _id: string; + firstName: string; + lastName: string; + image: string; + }; + messageContent: string; + receiver: { + _id: string; + firstName: string; + lastName: string; + }; + } + | undefined; + messageContent: string; +}; + +type Chat = { + _id: string; + isGroup: boolean; + name: string; + image: string; + messages: DirectMessage[]; + users: { + _id: string; + firstName: string; + lastName: string; + email: string; + image: string; + }[]; + unseenMessagesByUsers: string; +}; export default function chat(): JSX.Element { const { t } = useTranslation('translation', { - keyPrefix: 'chat', + keyPrefix: 'userChat', }); const { t: tCommon } = useTranslation('common'); const [hideDrawer, setHideDrawer] = useState(null); - const [chats, setChats] = useState([]); + const [chats, setChats] = useState([]); const [selectedContact, setSelectedContact] = useState(''); + const [filterType, setFilterType] = useState('all'); const { getItem } = useLocalStorage(); const userId = getItem('userId'); @@ -74,6 +126,25 @@ export default function chat(): JSX.Element { }; }, []); + React.useEffect(() => { + if (filterType === 'all') { + chatsListRefetch(); + if (chatsListData && chatsListData.chatsByUserId) { + setChats(chatsListData.chatsByUserId); + } + } else if (filterType === 'unread') { + unreadChatListRefetch(); + if (unreadChatListData && unreadChatListData.getUnreadChatsByUserId) { + setChats(unreadChatListData.getUnreadChatsByUserId); + } + } else if (filterType === 'group') { + groupChatListRefetch(); + if (groupChatListData && groupChatListData.getGroupChatsByUserId) { + setChats(groupChatListData.getGroupChatsByUserId); + } + } + }, [filterType]); + const [createDirectChatModalisOpen, setCreateDirectChatModalisOpen] = useState(false); @@ -105,60 +176,40 @@ export default function chat(): JSX.Element { }, }); + const { data: groupChatListData, refetch: groupChatListRefetch } = + useQuery(GROUP_CHAT_LIST); + + const { data: unreadChatListData, refetch: unreadChatListRefetch } = + useQuery(UNREAD_CHAT_LIST); + + const [markChatMessagesAsRead] = useMutation(MARK_CHAT_MESSAGES_AS_READ, { + variables: { + chatId: selectedContact, + userId: userId, + }, + }); + + useEffect(() => { + markChatMessagesAsRead().then(() => { + chatsListRefetch({ id: userId }); + }); + }, [selectedContact]); + React.useEffect(() => { - if (chatsListData) { + if (chatsListData && chatsListData?.chatsByUserId.length) { setChats(chatsListData.chatsByUserId); } }, [chatsListData]); - // const handleSearch = (value: string): void => { - // setFilterName(value); - - // contactRefetch(); - // }; - // const handleSearchByEnter = (e: any): void => { - // if (e.key === 'Enter') { - // const { value } = e.target; - // handleSearch(value); - // } - // }; - // const handleSearchByBtnClick = (): void => { - // const value = - // (document.getElementById('searchChats') as HTMLInputElement)?.value || ''; - // handleSearch(value); - // }; - return ( <> - {hideDrawer ? ( - - ) : ( - - )} -
-

Messages

+

{t('messages')}

- New Chat + {t('newChat')} - New Group Chat + {t('newGroupChat')} Starred Messages @@ -188,45 +239,102 @@ export default function chat(): JSX.Element {
{chatsListLoading ? (
- Loading... + {tCommon('loading')}
) : ( -
- {!!chats.length && - chats.map((chat: any) => { - const cardProps: InterfaceContactCardProps = { - id: chat._id, - title: !chat.isGroup - ? chat.users[0]?._id === userId - ? `${chat.users[1]?.firstName} ${chat.users[1]?.lastName}` - : `${chat.users[0]?.firstName} ${chat.users[0]?.lastName}` - : chat.name, - image: chat.isGroup - ? userId - ? chat.users[1]?.image - : chat.users[0]?.image - : chat.image, - setSelectedContact, - selectedContact, - isGroup: chat.isGroup, - }; - return ( - - ); - })} -
+ <> +
+ {/* three buttons to filter unread, all and group chats. All selected by default. */} + + + +
+ +
+ {!!chats.length && + chats.map((chat: Chat) => { + const cardProps: InterfaceContactCardProps = { + id: chat._id, + title: !chat.isGroup + ? chat.users[0]?._id === userId + ? `${chat.users[1]?.firstName} ${chat.users[1]?.lastName}` + : `${chat.users[0]?.firstName} ${chat.users[0]?.lastName}` + : chat.name, + image: chat.isGroup + ? chat.image + : userId + ? chat.users[1]?.image + : chat.users[0]?.image, + setSelectedContact, + selectedContact, + isGroup: chat.isGroup, + unseenMessages: JSON.parse( + chat.unseenMessagesByUsers, + )[userId], + lastMessage: + chat.messages[chat.messages.length - 1] + ?.messageContent, + }; + return ( + + ); + })} +
+ )}
- +
diff --git a/src/screens/UserPortal/Events/Events.spec.tsx b/src/screens/UserPortal/Events/Events.spec.tsx index 646f5052f0..0e49402019 100644 --- a/src/screens/UserPortal/Events/Events.spec.tsx +++ b/src/screens/UserPortal/Events/Events.spec.tsx @@ -98,6 +98,7 @@ const MOCKS = [ recurring: false, isPublic: true, isRegisterable: false, + createChat: false, creator: { _id: '63d649417ffe6e4d5174ea32', firstName: 'Noble', @@ -129,6 +130,7 @@ const MOCKS = [ recurring: false, isPublic: true, isRegisterable: true, + createChat: true, creator: { _id: '63d649417ffe6e4d5174ea32', firstName: 'Noble', @@ -179,6 +181,7 @@ const MOCKS = [ recurring: false, isPublic: true, isRegisterable: false, + createChat: false, creator: { _id: '63d649417ffe6e4d5174ea32', firstName: 'Noble', @@ -207,13 +210,95 @@ const MOCKS = [ variables: { title: 'testEventTitle', description: 'testEventDescription', + isPublic: true, + recurring: false, + isRegisterable: true, + organizationId: '', + startDate: dayjs(new Date()).format('YYYY-MM-DD'), + endDate: dayjs(new Date()).format('YYYY-MM-DD'), + allDay: true, location: 'testEventLocation', + startTime: null, + endTime: null, + createChat: false, + }, + }, + result: { + data: { + createEvent: { + _id: '2', + }, + }, + }, + }, + { + request: { + query: CREATE_EVENT_MUTATION, + variables: { + title: 'testEventTitle', + description: 'testEventDescription', + isPublic: true, + recurring: false, + isRegisterable: true, + organizationId: '', + startDate: dayjs(new Date()).format('YYYY-MM-DD'), + endDate: dayjs(new Date()).format('YYYY-MM-DD'), + allDay: true, + location: 'testEventLocation', + startTime: null, + endTime: null, + createChat: false, + }, + }, + result: { + data: { + createEvent: { + _id: '2', + }, + }, + }, + }, + { + request: { + query: CREATE_EVENT_MUTATION, + variables: { + title: 'testEventTitle', + description: 'testEventDescription', isPublic: true, recurring: false, isRegisterable: true, organizationId: '', startDate: dayjs(new Date()).format('YYYY-MM-DD'), endDate: dayjs(new Date()).format('YYYY-MM-DD'), + allDay: true, + location: 'testEventLocation', + startTime: null, + endTime: null, + createChat: false, + }, + }, + result: { + data: { + createEvent: { + _id: '2', + }, + }, + }, + }, + { + request: { + query: CREATE_EVENT_MUTATION, + variables: { + title: 'testEventTitle', + description: 'testEventDescription', + location: 'testEventLocation', + isPublic: true, + recurring: false, + isRegisterable: true, + createChat: false, + organizationId: '', + startDate: dayjs(new Date()).format('YYYY-MM-DD'), + endDate: dayjs(new Date()).format('YYYY-MM-DD'), allDay: false, startTime: '08:00:00', endTime: '10:00:00', @@ -233,13 +318,149 @@ const MOCKS = [ variables: { title: 'testEventTitle', description: 'testEventDescription', + isPublic: true, + recurring: false, + isRegisterable: true, + organizationId: '', + startDate: '2024-10-27', + endDate: '2024-10-27', + allDay: false, location: 'testEventLocation', + startTime: '08:00:00Z', + endTime: '10:00:00Z', + createChat: false, + }, + }, + result: { + data: { + createEvent: { + _id: '2', + }, + }, + }, + }, + { + request: { + query: CREATE_EVENT_MUTATION, + variables: { + title: 'testEventTitle', + description: 'testEventDescription', isPublic: true, recurring: false, isRegisterable: true, organizationId: '', startDate: dayjs(new Date()).format('YYYY-MM-DD'), endDate: dayjs(new Date()).format('YYYY-MM-DD'), + allDay: false, + location: 'testEventLocation', + startTime: '08:00:00Z', + endTime: '10:00:00Z', + createChat: false, + }, + }, + result: { + data: { + createEvent: { + _id: '2', + }, + }, + }, + }, + { + request: { + query: CREATE_EVENT_MUTATION, + variables: { + title: 'testEventTitle', + description: 'testEventDescription', + isPublic: true, + recurring: false, + isRegisterable: true, + organizationId: '', + startDate: dayjs(new Date()).format('YYYY-MM-DD'), + endDate: dayjs(new Date()).format('YYYY-MM-DD'), + allDay: false, + location: 'testEventLocation', + startTime: '08:00:00Z', + endTime: '10:00:00Z', + createChat: false, + }, + }, + result: { + data: { + createEvent: { + _id: '2', + }, + }, + }, + }, + { + request: { + query: CREATE_EVENT_MUTATION, + variables: { + title: 'testEventTitle', + description: 'testEventDescription', + location: 'testEventLocation', + isPublic: true, + recurring: false, + isRegisterable: true, + createChat: false, + organizationId: '', + startDate: dayjs(new Date()).format('YYYY-MM-DD'), + endDate: dayjs(new Date()).format('YYYY-MM-DD'), + allDay: false, + startTime: '08:00:00', + endTime: '10:00:00', + }, + }, + result: { + data: { + createEvent: { + _id: '2', + }, + }, + }, + }, + { + request: { + query: CREATE_EVENT_MUTATION, + variables: { + title: 'testEventTitle', + description: 'testEventDescription', + location: 'testEventLocation', + isPublic: true, + recurring: false, + isRegisterable: true, + createChat: false, + organizationId: '', + startDate: dayjs(new Date()).format('YYYY-MM-DD'), + endDate: dayjs(new Date()).format('YYYY-MM-DD'), + allDay: false, + startTime: '08:00:00', + endTime: '10:00:00', + }, + }, + result: { + data: { + createEvent: { + _id: '2', + }, + }, + }, + }, + { + request: { + query: CREATE_EVENT_MUTATION, + variables: { + title: 'testEventTitle', + description: 'testEventDescription', + location: 'testEventLocation', + isPublic: true, + recurring: false, + isRegisterable: true, + createChat: true, + organizationId: '', + startDate: dayjs(new Date()).format('YYYY-MM-DD'), + endDate: dayjs(new Date()).format('YYYY-MM-DD'), allDay: true, startTime: null, endTime: null, @@ -346,6 +567,9 @@ describe('Testing Events Screen [User Portal]', () => { userEvent.click(screen.getByTestId('recurringEventCheck')); userEvent.click(screen.getByTestId('recurringEventCheck')); + userEvent.click(screen.getByTestId('createChatCheck')); + userEvent.click(screen.getByTestId('createChatCheck')); + userEvent.click(screen.getByTestId('allDayEventCheck')); userEvent.click(screen.getByTestId('createEventBtn')); diff --git a/src/screens/UserPortal/Events/Events.tsx b/src/screens/UserPortal/Events/Events.tsx index aa8128c9e5..a6862c0a73 100644 --- a/src/screens/UserPortal/Events/Events.tsx +++ b/src/screens/UserPortal/Events/Events.tsx @@ -63,6 +63,7 @@ export default function events(): JSX.Element { const [endTime, setEndTime] = React.useState('10:00:00'); const [viewType, setViewType] = React.useState(ViewType.MONTH); const [createEventModal, setCreateEventmodalisOpen] = React.useState(false); + const [createChatCheck, setCreateChatCheck] = React.useState(false); const { orgId: organizationId } = useParams(); // Query to fetch events for the organization @@ -115,8 +116,9 @@ export default function events(): JSX.Element { endDate: dayjs(endDate).format('YYYY-MM-DD'), allDay: isAllDay, location: eventLocation, - startTime: !isAllDay ? startTime : null, - endTime: !isAllDay ? endTime : null, + startTime: !isAllDay ? startTime + 'Z' : null, + endTime: !isAllDay ? endTime + 'Z' : null, + createChat: createChatCheck, }, }); @@ -134,6 +136,7 @@ export default function events(): JSX.Element { } setCreateEventmodalisOpen(false); } catch (error: unknown) { + console.error('create event error', error); /* istanbul ignore next */ errorHandler(t, error); } @@ -390,6 +393,21 @@ export default function events(): JSX.Element { />
+
+
+ + + setCreateChatCheck(!createChatCheck) + } + /> +
+