|
56816
|
1975
|
5
|
2026-05-19T08:25:49.394039+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179149394_m2.jpg...
|
Firefox
|
NULL
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
NotionEditMISTOMWinaowheltrTavsco.s%9 JY-20676-del NotionEditMISTOMWinaowheltrTavsco.s%9 JY-20676-delete-Proletey© AskAnythingPromptDto.phpD Events© AsKAnytningPromptservice.ongc Historyservice.ongD AskJiminnyAiWAWSBillingManagementu cachew countryDatabaseDatadogDatettimeDeallnsightsN DealRisks1N GlasticSearch• EloquentEncoding• EncryptionDESD Faker• FeatureFlagsD FFMpeg• FileSystem• Gong_ cuzzienutoD KeyPoints• Kiosk_ LanquageDetectionW LOCKS• MathMediapioeline2 MobileSettinas• Model2 Notification• NudgeIM ParagranhBreaker1 PartitionedCookieM PlavbackPade• PlaylistProphetM PronhetAfD ProsperWorksM AuoncActivityController.php© AskAnythingPromptService.phpxphp api.phpAskAnythingControl© AskAnythingPrompt.pl© AutomatedReportsServicc) Automateakeport.pnpC AskAnythingFvicelest.png© Search.phpclass AskanychingPromptservicepublic function createl$shareUsers[] = $this->userRepository->findByUuid($userforeach ($shareGroupsUuids as $groupUuid) ($shareGroupsl] = Sthis->groupRepository->findByUuid($g$prompt = $this->askAnythingRepository->createPrompt($target,$title,$content,$shareUsers,ssharebroups.return new AskAnythingPromptDtoCsprompt->qetuu1dosprompt->getlitleosprompt->gettontentor$target,$user->getUuid(),SshareGrouosUuids.$prompt->has reports,* Abaram arrau<string> Ssharelisenslluids* @param array<string> $shareGroupsUuids* @throws InvalidArgumentExceptionpublic function edit(AskAnythingPrompt $prompt,User $user,string $title,string $content,AinnalYchanol concltttanearray ssharebroupsuu1ds): AskAnythingPromptDto {...}167public function deletedAskAnvthingPromot SpromotUser SuserLukas Kovalik s No..A HomeNo upcoming events^ View allNew page• WorkHubspot API callsS Hubspot© CRMWork KnowledgeE DSK Report 2025E DSK Report 2024€ Transactions@ Report 2023ravonte,O YEAR 2026ã App replacementRead laterO LOGSReport 2024VideosTodo@ TestG DailyAgents— New agentWorkspace* Quick Note• Work• Knowledge*e Ideas@ Finance hubE Home views( Integration-appNew chat *o"suppont Dally • In 3n 30m100% L&• Tue 19 May 11:25:49ah Share v*...Work• Jira ticket# TodayFs YesterdavEa Sorint 78 more…цж9лE Date: Today v° + FilterResetAa NameSave for everyone~= URLDelete saved search and panorama prompt+ New paqeF, SprintAa NameG Sprint 1 Q1@ Sprint 2 Q1m Date• TypeJanuary 5. 2026 → January 20, 202 Retrolanuary 21. 2026 → Cahruary 2.201 Petro-Sorint 3 @1February 4. 2026 → Februarv 17.20 R@ Sprint 4 Q1February 18, 2026 → March 3, 202€ Retro" Sorint 5 01March 4. 2026 → March 17. 20261 Sprint 6 Q1March 10 2006 A March 21 2026"Sorint7 o1Aorl 1. 2026 • Aorll 14. 2026@ Sprint 8 Q1+ New pageApril 15, 2026 April 28, 2026DailyE Tableee This monthEe TodavAa NameРдл=t Date• Туре© CrealDelete saved search and panorama prompt" CreatedMay 19. 2026 10:09*Done—DateMay 19, 20267 Parent itemRelated Ticket |EmptyStatusEmoty¾ Sub-itemEmptyE TagsEmpty= URL7 # SprintEmpty4 Add a nronertvlcomments(L Add a comment.1add bool on list2. disable related reports3. validation on toggle enable if no Saved search or promptPress 'space' for Al or ""' for commands...
|
NULL
|
-2292731660568147296
|
NULL
|
idle
|
ocr
|
NULL
|
NotionEditMISTOMWinaowheltrTavsco.s%9 JY-20676-del NotionEditMISTOMWinaowheltrTavsco.s%9 JY-20676-delete-Proletey© AskAnythingPromptDto.phpD Events© AsKAnytningPromptservice.ongc Historyservice.ongD AskJiminnyAiWAWSBillingManagementu cachew countryDatabaseDatadogDatettimeDeallnsightsN DealRisks1N GlasticSearch• EloquentEncoding• EncryptionDESD Faker• FeatureFlagsD FFMpeg• FileSystem• Gong_ cuzzienutoD KeyPoints• Kiosk_ LanquageDetectionW LOCKS• MathMediapioeline2 MobileSettinas• Model2 Notification• NudgeIM ParagranhBreaker1 PartitionedCookieM PlavbackPade• PlaylistProphetM PronhetAfD ProsperWorksM AuoncActivityController.php© AskAnythingPromptService.phpxphp api.phpAskAnythingControl© AskAnythingPrompt.pl© AutomatedReportsServicc) Automateakeport.pnpC AskAnythingFvicelest.png© Search.phpclass AskanychingPromptservicepublic function createl$shareUsers[] = $this->userRepository->findByUuid($userforeach ($shareGroupsUuids as $groupUuid) ($shareGroupsl] = Sthis->groupRepository->findByUuid($g$prompt = $this->askAnythingRepository->createPrompt($target,$title,$content,$shareUsers,ssharebroups.return new AskAnythingPromptDtoCsprompt->qetuu1dosprompt->getlitleosprompt->gettontentor$target,$user->getUuid(),SshareGrouosUuids.$prompt->has reports,* Abaram arrau<string> Ssharelisenslluids* @param array<string> $shareGroupsUuids* @throws InvalidArgumentExceptionpublic function edit(AskAnythingPrompt $prompt,User $user,string $title,string $content,AinnalYchanol concltttanearray ssharebroupsuu1ds): AskAnythingPromptDto {...}167public function deletedAskAnvthingPromot SpromotUser SuserLukas Kovalik s No..A HomeNo upcoming events^ View allNew page• WorkHubspot API callsS Hubspot© CRMWork KnowledgeE DSK Report 2025E DSK Report 2024€ Transactions@ Report 2023ravonte,O YEAR 2026ã App replacementRead laterO LOGSReport 2024VideosTodo@ TestG DailyAgents— New agentWorkspace* Quick Note• Work• Knowledge*e Ideas@ Finance hubE Home views( Integration-appNew chat *o"suppont Dally • In 3n 30m100% L&• Tue 19 May 11:25:49ah Share v*...Work• Jira ticket# TodayFs YesterdavEa Sorint 78 more…цж9лE Date: Today v° + FilterResetAa NameSave for everyone~= URLDelete saved search and panorama prompt+ New paqeF, SprintAa NameG Sprint 1 Q1@ Sprint 2 Q1m Date• TypeJanuary 5. 2026 → January 20, 202 Retrolanuary 21. 2026 → Cahruary 2.201 Petro-Sorint 3 @1February 4. 2026 → Februarv 17.20 R@ Sprint 4 Q1February 18, 2026 → March 3, 202€ Retro" Sorint 5 01March 4. 2026 → March 17. 20261 Sprint 6 Q1March 10 2006 A March 21 2026"Sorint7 o1Aorl 1. 2026 • Aorll 14. 2026@ Sprint 8 Q1+ New pageApril 15, 2026 April 28, 2026DailyE Tableee This monthEe TodavAa NameРдл=t Date• Туре© CrealDelete saved search and panorama prompt" CreatedMay 19. 2026 10:09*Done—DateMay 19, 20267 Parent itemRelated Ticket |EmptyStatusEmoty¾ Sub-itemEmptyE TagsEmpty= URL7 # SprintEmpty4 Add a nronertvlcomments(L Add a comment.1add bool on list2. disable related reports3. validation on toggle enable if no Saved search or promptPress 'space' for Al or ""' for commands...
|
56814
|
NULL
|
NULL
|
NULL
|
|
56817
|
1975
|
6
|
2026-05-19T08:25:59.239006+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179159239_m2.jpg...
|
Firefox
|
NULL
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
NotionEditMISTOMWinaowheltrTavsco.s%9 JY-20676-del NotionEditMISTOMWinaowheltrTavsco.s%9 JY-20676-deleteProletey© AskAnythingPromptDto.phpD Events© AsKAnytningPromptservice.ongc Historyservice.ongD AskJiminnyAiWAWSBillingManagementu cachew countryDatabaseDatadogDatettimeDeallnsightsN DealRisks1N GlasticSearchM EloquentEncoding• EncryptionDESD Faker• FeatureFlagsD FFMpeg• FileSystem• Gong_ cuzzienutoD KeyPoints• Kiosk_ LanquageDetectionW LOCKS• MathMediapioeline2 MobileSettinas• Model2 Notification• NudgeIM ParagranhBreaker1 PartitionedCookieM PlavbackPade• PlaylistProphetM PronhetAfD ProsperWorksM AuoncActivityController.php© AskAnythingPromptService.phpxphp api.phpAskAnythingControl© AskAnythingPrompt.p© AutomatedReportsServicc) Automateakeport.pnpC AskAnythingFvicelest.png© Search.phpclass AskanythingPromptservicepublic function createl$shareUsers[] = $this->userRepository->findByUuid($userforeach ($shareGroupsUuids as $groupUuid) ($shareGroupsl] = Sthis->groupRepository->findByUuid($g$prompt = $this->askAnythingRepository->createPrompt($target,$title,$content,$shareUsers,ssharebroups.return new AskAnythingPromptDtoCsprompt->qetuu1dosprompt->getlitleosprompt->gettontentor$target,$user->getUuid(),SshareGrouosUuids.$prompt->has reports,* Abaram arrau<string> Ssharelisenslluids* @param array<string> $shareGroupsUuids* @throws InvalidArgumentExceptionpublic function edit(AskAnythingPrompt $prompt,User $user,string $title,string $content,AinnalYchanoll concltttanearray ssharebroupsuu1ds): AskAnythingPromptDto {...}public function deletedAskAnvthingPromot SpromotUser SuserLukas Kovalik's No..A Home• No upcoming events7 View allNew page• WorkHubspot API callsS Hubspot© CRM• Work KnowledgeE DSK Report 2025E DSK Report 2024€ Transactions@ Report 2023ravonte,O YEAR 2026ã App replacementRead laterO LOGSReport 2024VideosTodo@ TestG DailyAgents— New agentWorkspace* Quick NoteWork• KnowledgeRa Ideas@ Finance hubE Home views( Integration-appNew chat *o—Work= Work"suppont Dally • In 3h 30m100% Lz.• lue 1y May 11.20.09ah Sharev*...Work• Jira ticket# TodayFs Yesterdav=a Sorint 78 more,цж9лE Date: Today v° + FilterResetAa NameSave for everyone~= URLDelete saved search and panorama prompt+ New paqeF SprintAa NameG Sprint 1 Q1@ Sprint 2 Q1m Date• TypeJanuary 5. 2026 → January 20, 202 Retrolanuary 21. 2026 → Cahruary 2.201 Petro-Sorint 3 @1February 4. 2026 → Februarv 17.20 R@ Sprint 4 Q1February 18, 2026 → March 3, 202€ Retro" Sorint 5 01March 4. 2026 → March 17. 20261 Sprint 6 Q1March 10 2006 A March 21 2026"Sorint7 01Aorl 1. 2026 • Aorll 14. 2026@ Sprint 8 Q1+ New pageApril 15, 2026 April 28, 2026DailyE Tableee This monthEe TodavAa NameРдл≥t Date• Туре© CrealDelete saved search and panorama prompt" Created*Done—Date7 Parent itemRelated Ticket |Status¾ Sub-itemE Tags= URL7 # Sprint+ Add a propertycomments(L Add a comment.1add bool on listMay 19. 2026 10:09May 19, 2026EmptyEmptyEmptyEmpty2. disable related reports3. validation on toggle enable if no Saved search or promptPress 'space' for Al or ""' for commands...
|
NULL
|
-8899367523684062844
|
NULL
|
visual_change
|
ocr
|
NULL
|
NotionEditMISTOMWinaowheltrTavsco.s%9 JY-20676-del NotionEditMISTOMWinaowheltrTavsco.s%9 JY-20676-deleteProletey© AskAnythingPromptDto.phpD Events© AsKAnytningPromptservice.ongc Historyservice.ongD AskJiminnyAiWAWSBillingManagementu cachew countryDatabaseDatadogDatettimeDeallnsightsN DealRisks1N GlasticSearchM EloquentEncoding• EncryptionDESD Faker• FeatureFlagsD FFMpeg• FileSystem• Gong_ cuzzienutoD KeyPoints• Kiosk_ LanquageDetectionW LOCKS• MathMediapioeline2 MobileSettinas• Model2 Notification• NudgeIM ParagranhBreaker1 PartitionedCookieM PlavbackPade• PlaylistProphetM PronhetAfD ProsperWorksM AuoncActivityController.php© AskAnythingPromptService.phpxphp api.phpAskAnythingControl© AskAnythingPrompt.p© AutomatedReportsServicc) Automateakeport.pnpC AskAnythingFvicelest.png© Search.phpclass AskanythingPromptservicepublic function createl$shareUsers[] = $this->userRepository->findByUuid($userforeach ($shareGroupsUuids as $groupUuid) ($shareGroupsl] = Sthis->groupRepository->findByUuid($g$prompt = $this->askAnythingRepository->createPrompt($target,$title,$content,$shareUsers,ssharebroups.return new AskAnythingPromptDtoCsprompt->qetuu1dosprompt->getlitleosprompt->gettontentor$target,$user->getUuid(),SshareGrouosUuids.$prompt->has reports,* Abaram arrau<string> Ssharelisenslluids* @param array<string> $shareGroupsUuids* @throws InvalidArgumentExceptionpublic function edit(AskAnythingPrompt $prompt,User $user,string $title,string $content,AinnalYchanoll concltttanearray ssharebroupsuu1ds): AskAnythingPromptDto {...}public function deletedAskAnvthingPromot SpromotUser SuserLukas Kovalik's No..A Home• No upcoming events7 View allNew page• WorkHubspot API callsS Hubspot© CRM• Work KnowledgeE DSK Report 2025E DSK Report 2024€ Transactions@ Report 2023ravonte,O YEAR 2026ã App replacementRead laterO LOGSReport 2024VideosTodo@ TestG DailyAgents— New agentWorkspace* Quick NoteWork• KnowledgeRa Ideas@ Finance hubE Home views( Integration-appNew chat *o—Work= Work"suppont Dally • In 3h 30m100% Lz.• lue 1y May 11.20.09ah Sharev*...Work• Jira ticket# TodayFs Yesterdav=a Sorint 78 more,цж9лE Date: Today v° + FilterResetAa NameSave for everyone~= URLDelete saved search and panorama prompt+ New paqeF SprintAa NameG Sprint 1 Q1@ Sprint 2 Q1m Date• TypeJanuary 5. 2026 → January 20, 202 Retrolanuary 21. 2026 → Cahruary 2.201 Petro-Sorint 3 @1February 4. 2026 → Februarv 17.20 R@ Sprint 4 Q1February 18, 2026 → March 3, 202€ Retro" Sorint 5 01March 4. 2026 → March 17. 20261 Sprint 6 Q1March 10 2006 A March 21 2026"Sorint7 01Aorl 1. 2026 • Aorll 14. 2026@ Sprint 8 Q1+ New pageApril 15, 2026 April 28, 2026DailyE Tableee This monthEe TodavAa NameРдл≥t Date• Туре© CrealDelete saved search and panorama prompt" Created*Done—Date7 Parent itemRelated Ticket |Status¾ Sub-itemE Tags= URL7 # Sprint+ Add a propertycomments(L Add a comment.1add bool on listMay 19. 2026 10:09May 19, 2026EmptyEmptyEmptyEmpty2. disable related reports3. validation on toggle enable if no Saved search or promptPress 'space' for Al or ""' for commands...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
56818
|
1975
|
7
|
2026-05-19T08:26:02.276853+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179162276_m2.jpg...
|
Firefox
|
NULL
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
NotionEditMISTOMWinaowheltrTavsco.s%9 JY-20676-del NotionEditMISTOMWinaowheltrTavsco.s%9 JY-20676-deleteProletey© AskAnythingPromptDto.phpD Events© AsKAnytningPromptservice.ongc Historyservice.ongD AskJiminnyAiWAWSBillingManagementu cachew countryDatabaseDatadogDatettimeDeallnsightsN DealRisks1N GlasticSearchM EloquentEncoding• EncryptionDESD Faker• FeatureFlagsD FFMpeg• FileSystem• Gong_ cuzzienutoD KeyPoints• Kiosk_ LanquageDetectionW LOCKS• MathMediapioeline2 MobileSettinas• Model2 Notification• NudgeIM ParagranhBreaker1 PartitionedCookieM PlavbackPade• PlaylistProphetM PronhetAfD ProsperWorksM AuoncActivityController.php© AskAnythingPromptService.phpxphp api.phpAskAnythingControl© AskAnythingPrompt.p© AutomatedReportsServicc) Automateakeport.pnpC AskAnythingFvicelest.png© Search.phpclass AskanythingPromptservicepublic function createl$shareUsers[] = $this->userRepository->findByUuid($userforeach ($shareGroupsUuids as SgroupUuid) ($shareGroupsl] = Sthis->groupRepository->findByUuid($g$prompt = $this->askAnythingRepository->createPrompt($target,$title,$content,$shareUsers,ssharebroups.return new AskAnythingPromptDtoCsprompt->qetuu1dosprompt->getlitleosprompt->gettontentor$target,$user->getUuid(),SshareGrouosUuids.$prompt->has reports,* Abaram arrau<string> Ssharelisenslluids* @param array<string> $shareGroupsUuids* @throws InvalidArgumentExceptionpublic function edit(AskAnythingPrompt $prompt,User $user,string $title,string $content,AinnalYchanoll concltttanearray ssharebroupsuu1ds): AskAnythingPromptDto 4...,public function deletedAskAnvthingPromot SpromotUser SuserLukas Kovalik's No..A Home• No upcoming events^ View allNew page• WorkHubspot API callsS Hubspot© CRM• Work KnowledgeE DSK Report 2025E DSK Report 2024€ Transactions@ Report 2023ravonte,O YEAR 2026ã App replacementRead laterO LOGSReport 2024VideosTodo@ TestG DailyAgents— New agentWorkspace* Quick NoteWork• KnowledgeRa Ideas@ Finance hubE Home views( Integration-appNew chat *oE Work= Work"suppont Dally • In 3n 34 m100% Lz8• Tue 19 May 11:26:02ah Share v*...Work• Jira ticket# TodayFs Yesterdav=a Sorint 78 more,цж9лE Date: Today v° + FilterResetAa NameSave for everyone~= URLDelete saved search and panorama prompt+ New paqeF SprintAa NameG Sprint 1 Q1@ Sprint 2 Q1m Date• TypeJanuary 5. 2026 → January 20, 202 Retrolanuary 21. 2026 → Cahruary 2.201 Petro-Sorint 3 @1February 4. 2026 → Februarv 17.20 R@ Sprint 4 Q1February 18, 2026 → March 3, 202€ Retro" Sorint 5 01March 4. 2026 → March 17. 20261 Sprint 6 Q1March 10 2006 A March 21 2026"Sorint7 01Aorl 1. 2026 • Aorll 14. 2026@ Sprint 8 Q1+ New pageApril 15, 2026 April 28, 2026DailyE Tableee This monthEe TodavAa NameРдл≥t Date• Туре© CrealDelete saved search and panorama prompt" Created*Done—Date7 Parent itemRelated Ticket IStatus¾ Sub-itemE Tags= URL7 # Sprint+ Add a propertycomments(L Add a comment.1add bool on listMay 19. 2026 10:09May 19, 2026EmptyEmptyEmptyEmpty2. disable related reports3. validation on toggle enable if no Saved search or promptPress 'space' for Al or ""' for commands...
|
NULL
|
60531512052404109
|
NULL
|
visual_change
|
ocr
|
NULL
|
NotionEditMISTOMWinaowheltrTavsco.s%9 JY-20676-del NotionEditMISTOMWinaowheltrTavsco.s%9 JY-20676-deleteProletey© AskAnythingPromptDto.phpD Events© AsKAnytningPromptservice.ongc Historyservice.ongD AskJiminnyAiWAWSBillingManagementu cachew countryDatabaseDatadogDatettimeDeallnsightsN DealRisks1N GlasticSearchM EloquentEncoding• EncryptionDESD Faker• FeatureFlagsD FFMpeg• FileSystem• Gong_ cuzzienutoD KeyPoints• Kiosk_ LanquageDetectionW LOCKS• MathMediapioeline2 MobileSettinas• Model2 Notification• NudgeIM ParagranhBreaker1 PartitionedCookieM PlavbackPade• PlaylistProphetM PronhetAfD ProsperWorksM AuoncActivityController.php© AskAnythingPromptService.phpxphp api.phpAskAnythingControl© AskAnythingPrompt.p© AutomatedReportsServicc) Automateakeport.pnpC AskAnythingFvicelest.png© Search.phpclass AskanythingPromptservicepublic function createl$shareUsers[] = $this->userRepository->findByUuid($userforeach ($shareGroupsUuids as SgroupUuid) ($shareGroupsl] = Sthis->groupRepository->findByUuid($g$prompt = $this->askAnythingRepository->createPrompt($target,$title,$content,$shareUsers,ssharebroups.return new AskAnythingPromptDtoCsprompt->qetuu1dosprompt->getlitleosprompt->gettontentor$target,$user->getUuid(),SshareGrouosUuids.$prompt->has reports,* Abaram arrau<string> Ssharelisenslluids* @param array<string> $shareGroupsUuids* @throws InvalidArgumentExceptionpublic function edit(AskAnythingPrompt $prompt,User $user,string $title,string $content,AinnalYchanoll concltttanearray ssharebroupsuu1ds): AskAnythingPromptDto 4...,public function deletedAskAnvthingPromot SpromotUser SuserLukas Kovalik's No..A Home• No upcoming events^ View allNew page• WorkHubspot API callsS Hubspot© CRM• Work KnowledgeE DSK Report 2025E DSK Report 2024€ Transactions@ Report 2023ravonte,O YEAR 2026ã App replacementRead laterO LOGSReport 2024VideosTodo@ TestG DailyAgents— New agentWorkspace* Quick NoteWork• KnowledgeRa Ideas@ Finance hubE Home views( Integration-appNew chat *oE Work= Work"suppont Dally • In 3n 34 m100% Lz8• Tue 19 May 11:26:02ah Share v*...Work• Jira ticket# TodayFs Yesterdav=a Sorint 78 more,цж9лE Date: Today v° + FilterResetAa NameSave for everyone~= URLDelete saved search and panorama prompt+ New paqeF SprintAa NameG Sprint 1 Q1@ Sprint 2 Q1m Date• TypeJanuary 5. 2026 → January 20, 202 Retrolanuary 21. 2026 → Cahruary 2.201 Petro-Sorint 3 @1February 4. 2026 → Februarv 17.20 R@ Sprint 4 Q1February 18, 2026 → March 3, 202€ Retro" Sorint 5 01March 4. 2026 → March 17. 20261 Sprint 6 Q1March 10 2006 A March 21 2026"Sorint7 01Aorl 1. 2026 • Aorll 14. 2026@ Sprint 8 Q1+ New pageApril 15, 2026 April 28, 2026DailyE Tableee This monthEe TodavAa NameРдл≥t Date• Туре© CrealDelete saved search and panorama prompt" Created*Done—Date7 Parent itemRelated Ticket IStatus¾ Sub-itemE Tags= URL7 # Sprint+ Add a propertycomments(L Add a comment.1add bool on listMay 19. 2026 10:09May 19, 2026EmptyEmptyEmptyEmpty2. disable related reports3. validation on toggle enable if no Saved search or promptPress 'space' for Al or ""' for commands...
|
56817
|
NULL
|
NULL
|
NULL
|
|
56820
|
1975
|
8
|
2026-05-19T08:26:13.717535+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179173717_m2.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\AskAnything;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
class AskAnythingPromptService
{
public function __construct(
private readonly AskAnythingRepository $askAnythingRepository,
private readonly UserRepository $userRepository,
private readonly GroupRepositoryInterface $groupRepository,
) {
}
/**
* @return array<AskAnythingPromptDto>
*/
public function get(User $user, AskAnythingPromptTarget $target): array
{
$prompts = $this->askAnythingRepository->findPromptsByUserAndTarget(
$user,
$target
);
$promptDtos = [];
foreach ($prompts as $prompt) {
$ownerUuid = null;
if ($prompt->getOwner() !== null) {
$ownerUuid = $prompt->getOwner()->getUuid();
}
$shareUsers = null;
$shareGroups = null;
// Provide users and groups only if owner of the prompt is current user
if ($prompt->getOwnerId() === $user->getId()) {
[$shareUsers, $shareGroups] = $this->getReceiverUuids($prompt);
}
$promptDtos[] = new AskAnythingPromptDto(
$prompt->getUuid(),
$prompt->getTitle(),
$prompt->getContent(),
$target,
$ownerUuid,
$shareUsers,
$shareGroups,
$prompt->getHasReports(),
);
}
return $promptDtos;
}
/**
* @param array<string> $shareUsersUuids
* @param array<string> $shareGroupsUuids
*/
public function create(
User $user,
string $title,
string $content,
AskAnythingPromptTarget $target,
array $shareUsersUuids,
array $shareGroupsUuids
): AskAnythingPromptDto {
$shareUsers = $shareGroups = [];
foreach ($shareUsersUuids as $userUuid) {
$shareUsers[] = $this->userRepository->findByUuid($userUuid);
}
foreach ($shareGroupsUuids as $groupUuid) {
$shareGroups[] = $this->groupRepository->findByUuid($groupUuid);
}
$prompt = $this->askAnythingRepository->createPrompt(
$user,
$target,
$title,
$content,
$shareUsers,
$shareGroups,
);
return new AskAnythingPromptDto(
$prompt->getUuid(),
$prompt->getTitle(),
$prompt->getContent(),
$target,
$user->getUuid(),
$shareUsersUuids,
$shareGroupsUuids,
$prompt->has_reports,
);
}
/**
* @param array<string> $shareUsersUuids
* @param array<string> $shareGroupsUuids
*
* @throws InvalidArgumentException
*/
public function edit(
AskAnythingPrompt $prompt,
User $user,
string $title,
string $content,
array $shareUsersUuids,
array $shareGroupsUuids
): AskAnythingPromptDto {
$shareUsers = $shareGroups = [];
foreach ($shareUsersUuids as $userUuid) {
$shareUsers[] = $this->userRepository->findByUuid($userUuid);
}
foreach ($shareGroupsUuids as $groupUuid) {
$shareGroups[] = $this->groupRepository->findByUuid($groupUuid);
}
if ($prompt->isDefaultPrompt()) {
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
$newPrompt = $this->askAnythingRepository->createPrompt(
$user,
$prompt->getTarget(),
$title,
$content,
$shareUsers,
$shareGroups,
);
} elseif ($prompt->getOwnerId() === $user->getId()) {
$newPrompt = $this->askAnythingRepository->editPrompt(
$prompt,
$title,
$content,
$shareUsers,
$shareGroups,
);
} else {
throw new InvalidArgumentException('Edit not allowed for prompt ' . $prompt->getUuid());
}
return new AskAnythingPromptDto(
$newPrompt->getUuid(),
$newPrompt->getTitle(),
$newPrompt->getContent(),
$newPrompt->getTarget(),
$user->getUuid(),
$shareUsersUuids,
$shareGroupsUuids,
$newPrompt->has_reports,
);
}
public function delete(
AskAnythingPrompt $prompt,
User $user
): AskAnythingPrompt {
if ($prompt->isDefaultPrompt()) {
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
} elseif ($prompt->getOwnerId() === $user->getId()) {
$userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);
$userPrompt?->delete();
// For each relation, re-create the prompt for the receiver as their own
$this->recreatePromptsForEachRelation($prompt);
// Finally, delete the prompt
$this->deletePromptIfNoRelations($prompt);
} else {
$userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);
$groupPrompt = $this->askAnythingRepository->findSharedPromptByUserGroup($prompt->getId(), $user);
// If the prompt is shared directly with the user, then "unshare" it
if ($userPrompt instanceof UserAskAnythingPrompt && $groupPrompt === null) {
$userPrompt->delete();
$this->deletePromptIfNoRelations($prompt);
} elseif ($groupPrompt instanceof UserAskAnythingPrompt) {
// If the prompt is shared with the user and the group, then hide it for this user
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
} else {
throw new InvalidArgumentException('Unknown delete allowance for prompt ' . $prompt->getUuid());
}
}
return $prompt;
}
public function reorder(
User $user,
array $promptUuids,
): void {
foreach ($promptUuids as $index => $promptUuid) {
$prompt = $this->askAnythingRepository->getPromptByUuid($promptUuid);
$this->askAnythingRepository->orderPromptForUser($prompt, $user, $index + 1);
}
}
/**
* @param AskAnythingPrompt $prompt
*
* @return array[array<string>, array<string>]
*/
private function getReceiverUuids(AskAnythingPrompt $prompt): array
{
$shareUsers = [];
$shareGroups = [];
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedUser = $sharedPrompt->getUser();
if ($sharedUser instanceof User && $sharedUser->isStatusActive()) {
$shareUsers[] = $sharedUser->getUuid();
}
$sharedGroup = $sharedPrompt->getGroup();
if ($sharedGroup instanceof Group) {
$shareGroups[] = $sharedGroup->getUuid();
}
}
return [$shareUsers, $shareGroups];
}
private function deletePromptIfNoRelations(AskAnythingPrompt $prompt): void
{
if ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId())->isEmpty()) {
// Disable and orphan any AutomatedReports that use this prompt
$prompt->automatedReports()->withTrashed()->update([
'ask_anything_prompt_id' => null,
'status' => false,
]);
// Delete only if there are no other relations to it.
$this->askAnythingRepository->deletePrompt($prompt);
}
}
private function recreatePromptsForEachRelation(AskAnythingPrompt $prompt): void
{
[$sharedUsersIds, $sharedUsersRemovedIds] = $this->recreatePromptsForUserRelations($prompt);
$this->recreatePromptsForGroupRelations($prompt, $sharedUsersIds, $sharedUsersRemovedIds);
}
private function recreatePromptsForUserRelations(AskAnythingPrompt $prompt): array
{
$sharedUsersIds = [];
$sharedUsersRemovedIds = [];
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedUser = $sharedPrompt->getUser();
if ($sharedPrompt->isRemoved() === true) {
$sharedUsersRemovedIds[] = $sharedUser->getId();
}
if ($sharedPrompt->isRemoved() !== true && $sharedUser instanceof User && $sharedUser->isStatusActive()) {
$sharedUsersIds[] = $sharedUser->getId();
$this->askAnythingRepository->createPrompt(
$sharedUser,
$prompt->getTarget(),
$prompt->getTitle(),
$prompt->getContent(),
[],
[],
);
$sharedPrompt->delete();
}
}
return [$sharedUsersIds, $sharedUsersRemovedIds];
}
private function recreatePromptsForGroupRelations(AskAnythingPrompt $prompt, array $sharedUsersIds, array $sharedUsersRemovedIds): void
{
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedGroup = $sharedPrompt->getGroup();
if ($sharedGroup instanceof Group) {
foreach ($sharedGroup->getMembers() as $member) {
if (! in_array($member->getId(), $sharedUsersIds)
&& ! in_array($member->getId(), $sharedUsersRemovedIds)) {
$sharedUsersIds[] = $member->getId();
$this->askAnythingRepository->createPrompt(
$member,
$prompt->getTarget(),
$prompt->getTitle(),
$prompt->getContent(),
[],
[],
);
}
}
$sharedPrompt->delete();
}
}
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.098071806,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"4","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.007978723,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.007978723,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\AskAnything;\n\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\n\nclass AskAnythingPromptService\n{\n public function __construct(\n private readonly AskAnythingRepository $askAnythingRepository,\n private readonly UserRepository $userRepository,\n private readonly GroupRepositoryInterface $groupRepository,\n ) {\n }\n\n /**\n * @return array<AskAnythingPromptDto>\n */\n public function get(User $user, AskAnythingPromptTarget $target): array\n {\n $prompts = $this->askAnythingRepository->findPromptsByUserAndTarget(\n $user,\n $target\n );\n\n $promptDtos = [];\n foreach ($prompts as $prompt) {\n $ownerUuid = null;\n if ($prompt->getOwner() !== null) {\n $ownerUuid = $prompt->getOwner()->getUuid();\n }\n $shareUsers = null;\n $shareGroups = null;\n\n // Provide users and groups only if owner of the prompt is current user\n if ($prompt->getOwnerId() === $user->getId()) {\n [$shareUsers, $shareGroups] = $this->getReceiverUuids($prompt);\n }\n\n $promptDtos[] = new AskAnythingPromptDto(\n $prompt->getUuid(),\n $prompt->getTitle(),\n $prompt->getContent(),\n $target,\n $ownerUuid,\n $shareUsers,\n $shareGroups,\n $prompt->getHasReports(),\n );\n }\n\n return $promptDtos;\n }\n\n /**\n * @param array<string> $shareUsersUuids\n * @param array<string> $shareGroupsUuids\n */\n public function create(\n User $user,\n string $title,\n string $content,\n AskAnythingPromptTarget $target,\n array $shareUsersUuids,\n array $shareGroupsUuids\n ): AskAnythingPromptDto {\n\n $shareUsers = $shareGroups = [];\n foreach ($shareUsersUuids as $userUuid) {\n $shareUsers[] = $this->userRepository->findByUuid($userUuid);\n }\n foreach ($shareGroupsUuids as $groupUuid) {\n $shareGroups[] = $this->groupRepository->findByUuid($groupUuid);\n }\n\n $prompt = $this->askAnythingRepository->createPrompt(\n $user,\n $target,\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n\n return new AskAnythingPromptDto(\n $prompt->getUuid(),\n $prompt->getTitle(),\n $prompt->getContent(),\n $target,\n $user->getUuid(),\n $shareUsersUuids,\n $shareGroupsUuids,\n $prompt->has_reports,\n );\n }\n\n /**\n * @param array<string> $shareUsersUuids\n * @param array<string> $shareGroupsUuids\n *\n * @throws InvalidArgumentException\n */\n public function edit(\n AskAnythingPrompt $prompt,\n User $user,\n string $title,\n string $content,\n array $shareUsersUuids,\n array $shareGroupsUuids\n ): AskAnythingPromptDto {\n $shareUsers = $shareGroups = [];\n foreach ($shareUsersUuids as $userUuid) {\n $shareUsers[] = $this->userRepository->findByUuid($userUuid);\n }\n foreach ($shareGroupsUuids as $groupUuid) {\n $shareGroups[] = $this->groupRepository->findByUuid($groupUuid);\n }\n\n if ($prompt->isDefaultPrompt()) {\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n\n $newPrompt = $this->askAnythingRepository->createPrompt(\n $user,\n $prompt->getTarget(),\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n } elseif ($prompt->getOwnerId() === $user->getId()) {\n $newPrompt = $this->askAnythingRepository->editPrompt(\n $prompt,\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n } else {\n throw new InvalidArgumentException('Edit not allowed for prompt ' . $prompt->getUuid());\n }\n\n return new AskAnythingPromptDto(\n $newPrompt->getUuid(),\n $newPrompt->getTitle(),\n $newPrompt->getContent(),\n $newPrompt->getTarget(),\n $user->getUuid(),\n $shareUsersUuids,\n $shareGroupsUuids,\n $newPrompt->has_reports,\n );\n }\n\n public function delete(\n AskAnythingPrompt $prompt,\n User $user\n ): AskAnythingPrompt {\n if ($prompt->isDefaultPrompt()) {\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n } elseif ($prompt->getOwnerId() === $user->getId()) {\n $userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);\n $userPrompt?->delete();\n // For each relation, re-create the prompt for the receiver as their own\n $this->recreatePromptsForEachRelation($prompt);\n\n // Finally, delete the prompt\n $this->deletePromptIfNoRelations($prompt);\n } else {\n $userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);\n $groupPrompt = $this->askAnythingRepository->findSharedPromptByUserGroup($prompt->getId(), $user);\n\n // If the prompt is shared directly with the user, then \"unshare\" it\n if ($userPrompt instanceof UserAskAnythingPrompt && $groupPrompt === null) {\n $userPrompt->delete();\n $this->deletePromptIfNoRelations($prompt);\n } elseif ($groupPrompt instanceof UserAskAnythingPrompt) {\n // If the prompt is shared with the user and the group, then hide it for this user\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n } else {\n throw new InvalidArgumentException('Unknown delete allowance for prompt ' . $prompt->getUuid());\n }\n }\n\n return $prompt;\n }\n\n public function reorder(\n User $user,\n array $promptUuids,\n ): void {\n foreach ($promptUuids as $index => $promptUuid) {\n $prompt = $this->askAnythingRepository->getPromptByUuid($promptUuid);\n $this->askAnythingRepository->orderPromptForUser($prompt, $user, $index + 1);\n }\n }\n\n /**\n * @param AskAnythingPrompt $prompt\n *\n * @return array[array<string>, array<string>]\n */\n private function getReceiverUuids(AskAnythingPrompt $prompt): array\n {\n $shareUsers = [];\n $shareGroups = [];\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedUser = $sharedPrompt->getUser();\n if ($sharedUser instanceof User && $sharedUser->isStatusActive()) {\n $shareUsers[] = $sharedUser->getUuid();\n }\n $sharedGroup = $sharedPrompt->getGroup();\n if ($sharedGroup instanceof Group) {\n $shareGroups[] = $sharedGroup->getUuid();\n }\n }\n\n return [$shareUsers, $shareGroups];\n }\n\n private function deletePromptIfNoRelations(AskAnythingPrompt $prompt): void\n {\n if ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId())->isEmpty()) {\n // Disable and orphan any AutomatedReports that use this prompt\n $prompt->automatedReports()->withTrashed()->update([\n 'ask_anything_prompt_id' => null,\n 'status' => false,\n ]);\n\n // Delete only if there are no other relations to it.\n $this->askAnythingRepository->deletePrompt($prompt);\n }\n }\n\n private function recreatePromptsForEachRelation(AskAnythingPrompt $prompt): void\n {\n [$sharedUsersIds, $sharedUsersRemovedIds] = $this->recreatePromptsForUserRelations($prompt);\n $this->recreatePromptsForGroupRelations($prompt, $sharedUsersIds, $sharedUsersRemovedIds);\n }\n\n private function recreatePromptsForUserRelations(AskAnythingPrompt $prompt): array\n {\n $sharedUsersIds = [];\n $sharedUsersRemovedIds = [];\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedUser = $sharedPrompt->getUser();\n if ($sharedPrompt->isRemoved() === true) {\n $sharedUsersRemovedIds[] = $sharedUser->getId();\n }\n if ($sharedPrompt->isRemoved() !== true && $sharedUser instanceof User && $sharedUser->isStatusActive()) {\n $sharedUsersIds[] = $sharedUser->getId();\n $this->askAnythingRepository->createPrompt(\n $sharedUser,\n $prompt->getTarget(),\n $prompt->getTitle(),\n $prompt->getContent(),\n [],\n [],\n );\n $sharedPrompt->delete();\n }\n }\n\n return [$sharedUsersIds, $sharedUsersRemovedIds];\n }\n\n private function recreatePromptsForGroupRelations(AskAnythingPrompt $prompt, array $sharedUsersIds, array $sharedUsersRemovedIds): void\n {\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedGroup = $sharedPrompt->getGroup();\n if ($sharedGroup instanceof Group) {\n foreach ($sharedGroup->getMembers() as $member) {\n if (! in_array($member->getId(), $sharedUsersIds)\n && ! in_array($member->getId(), $sharedUsersRemovedIds)) {\n $sharedUsersIds[] = $member->getId();\n $this->askAnythingRepository->createPrompt(\n $member,\n $prompt->getTarget(),\n $prompt->getTitle(),\n $prompt->getContent(),\n [],\n [],\n );\n }\n }\n $sharedPrompt->delete();\n }\n }\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\AskAnything;\n\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\n\nclass AskAnythingPromptService\n{\n public function __construct(\n private readonly AskAnythingRepository $askAnythingRepository,\n private readonly UserRepository $userRepository,\n private readonly GroupRepositoryInterface $groupRepository,\n ) {\n }\n\n /**\n * @return array<AskAnythingPromptDto>\n */\n public function get(User $user, AskAnythingPromptTarget $target): array\n {\n $prompts = $this->askAnythingRepository->findPromptsByUserAndTarget(\n $user,\n $target\n );\n\n $promptDtos = [];\n foreach ($prompts as $prompt) {\n $ownerUuid = null;\n if ($prompt->getOwner() !== null) {\n $ownerUuid = $prompt->getOwner()->getUuid();\n }\n $shareUsers = null;\n $shareGroups = null;\n\n // Provide users and groups only if owner of the prompt is current user\n if ($prompt->getOwnerId() === $user->getId()) {\n [$shareUsers, $shareGroups] = $this->getReceiverUuids($prompt);\n }\n\n $promptDtos[] = new AskAnythingPromptDto(\n $prompt->getUuid(),\n $prompt->getTitle(),\n $prompt->getContent(),\n $target,\n $ownerUuid,\n $shareUsers,\n $shareGroups,\n $prompt->getHasReports(),\n );\n }\n\n return $promptDtos;\n }\n\n /**\n * @param array<string> $shareUsersUuids\n * @param array<string> $shareGroupsUuids\n */\n public function create(\n User $user,\n string $title,\n string $content,\n AskAnythingPromptTarget $target,\n array $shareUsersUuids,\n array $shareGroupsUuids\n ): AskAnythingPromptDto {\n\n $shareUsers = $shareGroups = [];\n foreach ($shareUsersUuids as $userUuid) {\n $shareUsers[] = $this->userRepository->findByUuid($userUuid);\n }\n foreach ($shareGroupsUuids as $groupUuid) {\n $shareGroups[] = $this->groupRepository->findByUuid($groupUuid);\n }\n\n $prompt = $this->askAnythingRepository->createPrompt(\n $user,\n $target,\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n\n return new AskAnythingPromptDto(\n $prompt->getUuid(),\n $prompt->getTitle(),\n $prompt->getContent(),\n $target,\n $user->getUuid(),\n $shareUsersUuids,\n $shareGroupsUuids,\n $prompt->has_reports,\n );\n }\n\n /**\n * @param array<string> $shareUsersUuids\n * @param array<string> $shareGroupsUuids\n *\n * @throws InvalidArgumentException\n */\n public function edit(\n AskAnythingPrompt $prompt,\n User $user,\n string $title,\n string $content,\n array $shareUsersUuids,\n array $shareGroupsUuids\n ): AskAnythingPromptDto {\n $shareUsers = $shareGroups = [];\n foreach ($shareUsersUuids as $userUuid) {\n $shareUsers[] = $this->userRepository->findByUuid($userUuid);\n }\n foreach ($shareGroupsUuids as $groupUuid) {\n $shareGroups[] = $this->groupRepository->findByUuid($groupUuid);\n }\n\n if ($prompt->isDefaultPrompt()) {\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n\n $newPrompt = $this->askAnythingRepository->createPrompt(\n $user,\n $prompt->getTarget(),\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n } elseif ($prompt->getOwnerId() === $user->getId()) {\n $newPrompt = $this->askAnythingRepository->editPrompt(\n $prompt,\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n } else {\n throw new InvalidArgumentException('Edit not allowed for prompt ' . $prompt->getUuid());\n }\n\n return new AskAnythingPromptDto(\n $newPrompt->getUuid(),\n $newPrompt->getTitle(),\n $newPrompt->getContent(),\n $newPrompt->getTarget(),\n $user->getUuid(),\n $shareUsersUuids,\n $shareGroupsUuids,\n $newPrompt->has_reports,\n );\n }\n\n public function delete(\n AskAnythingPrompt $prompt,\n User $user\n ): AskAnythingPrompt {\n if ($prompt->isDefaultPrompt()) {\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n } elseif ($prompt->getOwnerId() === $user->getId()) {\n $userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);\n $userPrompt?->delete();\n // For each relation, re-create the prompt for the receiver as their own\n $this->recreatePromptsForEachRelation($prompt);\n\n // Finally, delete the prompt\n $this->deletePromptIfNoRelations($prompt);\n } else {\n $userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);\n $groupPrompt = $this->askAnythingRepository->findSharedPromptByUserGroup($prompt->getId(), $user);\n\n // If the prompt is shared directly with the user, then \"unshare\" it\n if ($userPrompt instanceof UserAskAnythingPrompt && $groupPrompt === null) {\n $userPrompt->delete();\n $this->deletePromptIfNoRelations($prompt);\n } elseif ($groupPrompt instanceof UserAskAnythingPrompt) {\n // If the prompt is shared with the user and the group, then hide it for this user\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n } else {\n throw new InvalidArgumentException('Unknown delete allowance for prompt ' . $prompt->getUuid());\n }\n }\n\n return $prompt;\n }\n\n public function reorder(\n User $user,\n array $promptUuids,\n ): void {\n foreach ($promptUuids as $index => $promptUuid) {\n $prompt = $this->askAnythingRepository->getPromptByUuid($promptUuid);\n $this->askAnythingRepository->orderPromptForUser($prompt, $user, $index + 1);\n }\n }\n\n /**\n * @param AskAnythingPrompt $prompt\n *\n * @return array[array<string>, array<string>]\n */\n private function getReceiverUuids(AskAnythingPrompt $prompt): array\n {\n $shareUsers = [];\n $shareGroups = [];\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedUser = $sharedPrompt->getUser();\n if ($sharedUser instanceof User && $sharedUser->isStatusActive()) {\n $shareUsers[] = $sharedUser->getUuid();\n }\n $sharedGroup = $sharedPrompt->getGroup();\n if ($sharedGroup instanceof Group) {\n $shareGroups[] = $sharedGroup->getUuid();\n }\n }\n\n return [$shareUsers, $shareGroups];\n }\n\n private function deletePromptIfNoRelations(AskAnythingPrompt $prompt): void\n {\n if ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId())->isEmpty()) {\n // Disable and orphan any AutomatedReports that use this prompt\n $prompt->automatedReports()->withTrashed()->update([\n 'ask_anything_prompt_id' => null,\n 'status' => false,\n ]);\n\n // Delete only if there are no other relations to it.\n $this->askAnythingRepository->deletePrompt($prompt);\n }\n }\n\n private function recreatePromptsForEachRelation(AskAnythingPrompt $prompt): void\n {\n [$sharedUsersIds, $sharedUsersRemovedIds] = $this->recreatePromptsForUserRelations($prompt);\n $this->recreatePromptsForGroupRelations($prompt, $sharedUsersIds, $sharedUsersRemovedIds);\n }\n\n private function recreatePromptsForUserRelations(AskAnythingPrompt $prompt): array\n {\n $sharedUsersIds = [];\n $sharedUsersRemovedIds = [];\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedUser = $sharedPrompt->getUser();\n if ($sharedPrompt->isRemoved() === true) {\n $sharedUsersRemovedIds[] = $sharedUser->getId();\n }\n if ($sharedPrompt->isRemoved() !== true && $sharedUser instanceof User && $sharedUser->isStatusActive()) {\n $sharedUsersIds[] = $sharedUser->getId();\n $this->askAnythingRepository->createPrompt(\n $sharedUser,\n $prompt->getTarget(),\n $prompt->getTitle(),\n $prompt->getContent(),\n [],\n [],\n );\n $sharedPrompt->delete();\n }\n }\n\n return [$sharedUsersIds, $sharedUsersRemovedIds];\n }\n\n private function recreatePromptsForGroupRelations(AskAnythingPrompt $prompt, array $sharedUsersIds, array $sharedUsersRemovedIds): void\n {\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedGroup = $sharedPrompt->getGroup();\n if ($sharedGroup instanceof Group) {\n foreach ($sharedGroup->getMembers() as $member) {\n if (! in_array($member->getId(), $sharedUsersIds)\n && ! in_array($member->getId(), $sharedUsersRemovedIds)) {\n $sharedUsersIds[] = $member->getId();\n $this->askAnythingRepository->createPrompt(\n $member,\n $prompt->getTarget(),\n $prompt->getTitle(),\n $prompt->getContent(),\n [],\n [],\n );\n }\n }\n $sharedPrompt->delete();\n }\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.7124335,"top":0.10055866,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.72140956,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7287234,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"bounds":{"left":0.4481383,"top":0.09736632,"width":0.29288563,"height":0.8818835},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
8246594430560437790
|
1126917008115010046
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\AskAnything;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
class AskAnythingPromptService
{
public function __construct(
private readonly AskAnythingRepository $askAnythingRepository,
private readonly UserRepository $userRepository,
private readonly GroupRepositoryInterface $groupRepository,
) {
}
/**
* @return array<AskAnythingPromptDto>
*/
public function get(User $user, AskAnythingPromptTarget $target): array
{
$prompts = $this->askAnythingRepository->findPromptsByUserAndTarget(
$user,
$target
);
$promptDtos = [];
foreach ($prompts as $prompt) {
$ownerUuid = null;
if ($prompt->getOwner() !== null) {
$ownerUuid = $prompt->getOwner()->getUuid();
}
$shareUsers = null;
$shareGroups = null;
// Provide users and groups only if owner of the prompt is current user
if ($prompt->getOwnerId() === $user->getId()) {
[$shareUsers, $shareGroups] = $this->getReceiverUuids($prompt);
}
$promptDtos[] = new AskAnythingPromptDto(
$prompt->getUuid(),
$prompt->getTitle(),
$prompt->getContent(),
$target,
$ownerUuid,
$shareUsers,
$shareGroups,
$prompt->getHasReports(),
);
}
return $promptDtos;
}
/**
* @param array<string> $shareUsersUuids
* @param array<string> $shareGroupsUuids
*/
public function create(
User $user,
string $title,
string $content,
AskAnythingPromptTarget $target,
array $shareUsersUuids,
array $shareGroupsUuids
): AskAnythingPromptDto {
$shareUsers = $shareGroups = [];
foreach ($shareUsersUuids as $userUuid) {
$shareUsers[] = $this->userRepository->findByUuid($userUuid);
}
foreach ($shareGroupsUuids as $groupUuid) {
$shareGroups[] = $this->groupRepository->findByUuid($groupUuid);
}
$prompt = $this->askAnythingRepository->createPrompt(
$user,
$target,
$title,
$content,
$shareUsers,
$shareGroups,
);
return new AskAnythingPromptDto(
$prompt->getUuid(),
$prompt->getTitle(),
$prompt->getContent(),
$target,
$user->getUuid(),
$shareUsersUuids,
$shareGroupsUuids,
$prompt->has_reports,
);
}
/**
* @param array<string> $shareUsersUuids
* @param array<string> $shareGroupsUuids
*
* @throws InvalidArgumentException
*/
public function edit(
AskAnythingPrompt $prompt,
User $user,
string $title,
string $content,
array $shareUsersUuids,
array $shareGroupsUuids
): AskAnythingPromptDto {
$shareUsers = $shareGroups = [];
foreach ($shareUsersUuids as $userUuid) {
$shareUsers[] = $this->userRepository->findByUuid($userUuid);
}
foreach ($shareGroupsUuids as $groupUuid) {
$shareGroups[] = $this->groupRepository->findByUuid($groupUuid);
}
if ($prompt->isDefaultPrompt()) {
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
$newPrompt = $this->askAnythingRepository->createPrompt(
$user,
$prompt->getTarget(),
$title,
$content,
$shareUsers,
$shareGroups,
);
} elseif ($prompt->getOwnerId() === $user->getId()) {
$newPrompt = $this->askAnythingRepository->editPrompt(
$prompt,
$title,
$content,
$shareUsers,
$shareGroups,
);
} else {
throw new InvalidArgumentException('Edit not allowed for prompt ' . $prompt->getUuid());
}
return new AskAnythingPromptDto(
$newPrompt->getUuid(),
$newPrompt->getTitle(),
$newPrompt->getContent(),
$newPrompt->getTarget(),
$user->getUuid(),
$shareUsersUuids,
$shareGroupsUuids,
$newPrompt->has_reports,
);
}
public function delete(
AskAnythingPrompt $prompt,
User $user
): AskAnythingPrompt {
if ($prompt->isDefaultPrompt()) {
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
} elseif ($prompt->getOwnerId() === $user->getId()) {
$userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);
$userPrompt?->delete();
// For each relation, re-create the prompt for the receiver as their own
$this->recreatePromptsForEachRelation($prompt);
// Finally, delete the prompt
$this->deletePromptIfNoRelations($prompt);
} else {
$userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);
$groupPrompt = $this->askAnythingRepository->findSharedPromptByUserGroup($prompt->getId(), $user);
// If the prompt is shared directly with the user, then "unshare" it
if ($userPrompt instanceof UserAskAnythingPrompt && $groupPrompt === null) {
$userPrompt->delete();
$this->deletePromptIfNoRelations($prompt);
} elseif ($groupPrompt instanceof UserAskAnythingPrompt) {
// If the prompt is shared with the user and the group, then hide it for this user
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
} else {
throw new InvalidArgumentException('Unknown delete allowance for prompt ' . $prompt->getUuid());
}
}
return $prompt;
}
public function reorder(
User $user,
array $promptUuids,
): void {
foreach ($promptUuids as $index => $promptUuid) {
$prompt = $this->askAnythingRepository->getPromptByUuid($promptUuid);
$this->askAnythingRepository->orderPromptForUser($prompt, $user, $index + 1);
}
}
/**
* @param AskAnythingPrompt $prompt
*
* @return array[array<string>, array<string>]
*/
private function getReceiverUuids(AskAnythingPrompt $prompt): array
{
$shareUsers = [];
$shareGroups = [];
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedUser = $sharedPrompt->getUser();
if ($sharedUser instanceof User && $sharedUser->isStatusActive()) {
$shareUsers[] = $sharedUser->getUuid();
}
$sharedGroup = $sharedPrompt->getGroup();
if ($sharedGroup instanceof Group) {
$shareGroups[] = $sharedGroup->getUuid();
}
}
return [$shareUsers, $shareGroups];
}
private function deletePromptIfNoRelations(AskAnythingPrompt $prompt): void
{
if ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId())->isEmpty()) {
// Disable and orphan any AutomatedReports that use this prompt
$prompt->automatedReports()->withTrashed()->update([
'ask_anything_prompt_id' => null,
'status' => false,
]);
// Delete only if there are no other relations to it.
$this->askAnythingRepository->deletePrompt($prompt);
}
}
private function recreatePromptsForEachRelation(AskAnythingPrompt $prompt): void
{
[$sharedUsersIds, $sharedUsersRemovedIds] = $this->recreatePromptsForUserRelations($prompt);
$this->recreatePromptsForGroupRelations($prompt, $sharedUsersIds, $sharedUsersRemovedIds);
}
private function recreatePromptsForUserRelations(AskAnythingPrompt $prompt): array
{
$sharedUsersIds = [];
$sharedUsersRemovedIds = [];
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedUser = $sharedPrompt->getUser();
if ($sharedPrompt->isRemoved() === true) {
$sharedUsersRemovedIds[] = $sharedUser->getId();
}
if ($sharedPrompt->isRemoved() !== true && $sharedUser instanceof User && $sharedUser->isStatusActive()) {
$sharedUsersIds[] = $sharedUser->getId();
$this->askAnythingRepository->createPrompt(
$sharedUser,
$prompt->getTarget(),
$prompt->getTitle(),
$prompt->getContent(),
[],
[],
);
$sharedPrompt->delete();
}
}
return [$sharedUsersIds, $sharedUsersRemovedIds];
}
private function recreatePromptsForGroupRelations(AskAnythingPrompt $prompt, array $sharedUsersIds, array $sharedUsersRemovedIds): void
{
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedGroup = $sharedPrompt->getGroup();
if ($sharedGroup instanceof Group) {
foreach ($sharedGroup->getMembers() as $member) {
if (! in_array($member->getId(), $sharedUsersIds)
&& ! in_array($member->getId(), $sharedUsersRemovedIds)) {
$sharedUsersIds[] = $member->getId();
$this->askAnythingRepository->createPrompt(
$member,
$prompt->getTarget(),
$prompt->getTitle(),
$prompt->getContent(),
[],
[],
);
}
}
$sharedPrompt->delete();
}
}
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
56819
|
1974
|
6
|
2026-05-19T08:26:13.731721+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179173731_m1.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\AskAnything;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
class AskAnythingPromptService
{
public function __construct(
private readonly AskAnythingRepository $askAnythingRepository,
private readonly UserRepository $userRepository,
private readonly GroupRepositoryInterface $groupRepository,
) {
}
/**
* @return array<AskAnythingPromptDto>
*/
public function get(User $user, AskAnythingPromptTarget $target): array
{
$prompts = $this->askAnythingRepository->findPromptsByUserAndTarget(
$user,
$target
);
$promptDtos = [];
foreach ($prompts as $prompt) {
$ownerUuid = null;
if ($prompt->getOwner() !== null) {
$ownerUuid = $prompt->getOwner()->getUuid();
}
$shareUsers = null;
$shareGroups = null;
// Provide users and groups only if owner of the prompt is current user
if ($prompt->getOwnerId() === $user->getId()) {
[$shareUsers, $shareGroups] = $this->getReceiverUuids($prompt);
}
$promptDtos[] = new AskAnythingPromptDto(
$prompt->getUuid(),
$prompt->getTitle(),
$prompt->getContent(),
$target,
$ownerUuid,
$shareUsers,
$shareGroups,
$prompt->getHasReports(),
);
}
return $promptDtos;
}
/**
* @param array<string> $shareUsersUuids
* @param array<string> $shareGroupsUuids
*/
public function create(
User $user,
string $title,
string $content,
AskAnythingPromptTarget $target,
array $shareUsersUuids,
array $shareGroupsUuids
): AskAnythingPromptDto {
$shareUsers = $shareGroups = [];
foreach ($shareUsersUuids as $userUuid) {
$shareUsers[] = $this->userRepository->findByUuid($userUuid);
}
foreach ($shareGroupsUuids as $groupUuid) {
$shareGroups[] = $this->groupRepository->findByUuid($groupUuid);
}
$prompt = $this->askAnythingRepository->createPrompt(
$user,
$target,
$title,
$content,
$shareUsers,
$shareGroups,
);
return new AskAnythingPromptDto(
$prompt->getUuid(),
$prompt->getTitle(),
$prompt->getContent(),
$target,
$user->getUuid(),
$shareUsersUuids,
$shareGroupsUuids,
$prompt->has_reports,
);
}
/**
* @param array<string> $shareUsersUuids
* @param array<string> $shareGroupsUuids
*
* @throws InvalidArgumentException
*/
public function edit(
AskAnythingPrompt $prompt,
User $user,
string $title,
string $content,
array $shareUsersUuids,
array $shareGroupsUuids
): AskAnythingPromptDto {
$shareUsers = $shareGroups = [];
foreach ($shareUsersUuids as $userUuid) {
$shareUsers[] = $this->userRepository->findByUuid($userUuid);
}
foreach ($shareGroupsUuids as $groupUuid) {
$shareGroups[] = $this->groupRepository->findByUuid($groupUuid);
}
if ($prompt->isDefaultPrompt()) {
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
$newPrompt = $this->askAnythingRepository->createPrompt(
$user,
$prompt->getTarget(),
$title,
$content,
$shareUsers,
$shareGroups,
);
} elseif ($prompt->getOwnerId() === $user->getId()) {
$newPrompt = $this->askAnythingRepository->editPrompt(
$prompt,
$title,
$content,
$shareUsers,
$shareGroups,
);
} else {
throw new InvalidArgumentException('Edit not allowed for prompt ' . $prompt->getUuid());
}
return new AskAnythingPromptDto(
$newPrompt->getUuid(),
$newPrompt->getTitle(),
$newPrompt->getContent(),
$newPrompt->getTarget(),
$user->getUuid(),
$shareUsersUuids,
$shareGroupsUuids,
$newPrompt->has_reports,
);
}
public function delete(
AskAnythingPrompt $prompt,
User $user
): AskAnythingPrompt {
if ($prompt->isDefaultPrompt()) {
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
} elseif ($prompt->getOwnerId() === $user->getId()) {
$userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);
$userPrompt?->delete();
// For each relation, re-create the prompt for the receiver as their own
$this->recreatePromptsForEachRelation($prompt);
// Finally, delete the prompt
$this->deletePromptIfNoRelations($prompt);
} else {
$userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);
$groupPrompt = $this->askAnythingRepository->findSharedPromptByUserGroup($prompt->getId(), $user);
// If the prompt is shared directly with the user, then "unshare" it
if ($userPrompt instanceof UserAskAnythingPrompt && $groupPrompt === null) {
$userPrompt->delete();
$this->deletePromptIfNoRelations($prompt);
} elseif ($groupPrompt instanceof UserAskAnythingPrompt) {
// If the prompt is shared with the user and the group, then hide it for this user
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
} else {
throw new InvalidArgumentException('Unknown delete allowance for prompt ' . $prompt->getUuid());
}
}
return $prompt;
}
public function reorder(
User $user,
array $promptUuids,
): void {
foreach ($promptUuids as $index => $promptUuid) {
$prompt = $this->askAnythingRepository->getPromptByUuid($promptUuid);
$this->askAnythingRepository->orderPromptForUser($prompt, $user, $index + 1);
}
}
/**
* @param AskAnythingPrompt $prompt
*
* @return array[array<string>, array<string>]
*/
private function getReceiverUuids(AskAnythingPrompt $prompt): array
{
$shareUsers = [];
$shareGroups = [];
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedUser = $sharedPrompt->getUser();
if ($sharedUser instanceof User && $sharedUser->isStatusActive()) {
$shareUsers[] = $sharedUser->getUuid();
}
$sharedGroup = $sharedPrompt->getGroup();
if ($sharedGroup instanceof Group) {
$shareGroups[] = $sharedGroup->getUuid();
}
}
return [$shareUsers, $shareGroups];
}
private function deletePromptIfNoRelations(AskAnythingPrompt $prompt): void
{
if ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId())->isEmpty()) {
// Disable and orphan any AutomatedReports that use this prompt
$prompt->automatedReports()->withTrashed()->update([
'ask_anything_prompt_id' => null,
'status' => false,
]);
// Delete only if there are no other relations to it.
$this->askAnythingRepository->deletePrompt($prompt);
}
}
private function recreatePromptsForEachRelation(AskAnythingPrompt $prompt): void
{
[$sharedUsersIds, $sharedUsersRemovedIds] = $this->recreatePromptsForUserRelations($prompt);
$this->recreatePromptsForGroupRelations($prompt, $sharedUsersIds, $sharedUsersRemovedIds);
}
private function recreatePromptsForUserRelations(AskAnythingPrompt $prompt): array
{
$sharedUsersIds = [];
$sharedUsersRemovedIds = [];
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedUser = $sharedPrompt->getUser();
if ($sharedPrompt->isRemoved() === true) {
$sharedUsersRemovedIds[] = $sharedUser->getId();
}
if ($sharedPrompt->isRemoved() !== true && $sharedUser instanceof User && $sharedUser->isStatusActive()) {
$sharedUsersIds[] = $sharedUser->getId();
$this->askAnythingRepository->createPrompt(
$sharedUser,
$prompt->getTarget(),
$prompt->getTitle(),
$prompt->getContent(),
[],
[],
);
$sharedPrompt->delete();
}
}
return [$sharedUsersIds, $sharedUsersRemovedIds];
}
private function recreatePromptsForGroupRelations(AskAnythingPrompt $prompt, array $sharedUsersIds, array $sharedUsersRemovedIds): void
{
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedGroup = $sharedPrompt->getGroup();
if ($sharedGroup instanceof Group) {
foreach ($sharedGroup->getMembers() as $member) {
if (! in_array($member->getId(), $sharedUsersIds)
&& ! in_array($member->getId(), $sharedUsersRemovedIds)) {
$sharedUsersIds[] = $member->getId();
$this->askAnythingRepository->createPrompt(
$member,
$prompt->getTarget(),
$prompt->getTitle(),
$prompt->getContent(),
[],
[],
);
}
}
$sharedPrompt->delete();
}
}
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"4","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.016666668,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.016666668,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\AskAnything;\n\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\n\nclass AskAnythingPromptService\n{\n public function __construct(\n private readonly AskAnythingRepository $askAnythingRepository,\n private readonly UserRepository $userRepository,\n private readonly GroupRepositoryInterface $groupRepository,\n ) {\n }\n\n /**\n * @return array<AskAnythingPromptDto>\n */\n public function get(User $user, AskAnythingPromptTarget $target): array\n {\n $prompts = $this->askAnythingRepository->findPromptsByUserAndTarget(\n $user,\n $target\n );\n\n $promptDtos = [];\n foreach ($prompts as $prompt) {\n $ownerUuid = null;\n if ($prompt->getOwner() !== null) {\n $ownerUuid = $prompt->getOwner()->getUuid();\n }\n $shareUsers = null;\n $shareGroups = null;\n\n // Provide users and groups only if owner of the prompt is current user\n if ($prompt->getOwnerId() === $user->getId()) {\n [$shareUsers, $shareGroups] = $this->getReceiverUuids($prompt);\n }\n\n $promptDtos[] = new AskAnythingPromptDto(\n $prompt->getUuid(),\n $prompt->getTitle(),\n $prompt->getContent(),\n $target,\n $ownerUuid,\n $shareUsers,\n $shareGroups,\n $prompt->getHasReports(),\n );\n }\n\n return $promptDtos;\n }\n\n /**\n * @param array<string> $shareUsersUuids\n * @param array<string> $shareGroupsUuids\n */\n public function create(\n User $user,\n string $title,\n string $content,\n AskAnythingPromptTarget $target,\n array $shareUsersUuids,\n array $shareGroupsUuids\n ): AskAnythingPromptDto {\n\n $shareUsers = $shareGroups = [];\n foreach ($shareUsersUuids as $userUuid) {\n $shareUsers[] = $this->userRepository->findByUuid($userUuid);\n }\n foreach ($shareGroupsUuids as $groupUuid) {\n $shareGroups[] = $this->groupRepository->findByUuid($groupUuid);\n }\n\n $prompt = $this->askAnythingRepository->createPrompt(\n $user,\n $target,\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n\n return new AskAnythingPromptDto(\n $prompt->getUuid(),\n $prompt->getTitle(),\n $prompt->getContent(),\n $target,\n $user->getUuid(),\n $shareUsersUuids,\n $shareGroupsUuids,\n $prompt->has_reports,\n );\n }\n\n /**\n * @param array<string> $shareUsersUuids\n * @param array<string> $shareGroupsUuids\n *\n * @throws InvalidArgumentException\n */\n public function edit(\n AskAnythingPrompt $prompt,\n User $user,\n string $title,\n string $content,\n array $shareUsersUuids,\n array $shareGroupsUuids\n ): AskAnythingPromptDto {\n $shareUsers = $shareGroups = [];\n foreach ($shareUsersUuids as $userUuid) {\n $shareUsers[] = $this->userRepository->findByUuid($userUuid);\n }\n foreach ($shareGroupsUuids as $groupUuid) {\n $shareGroups[] = $this->groupRepository->findByUuid($groupUuid);\n }\n\n if ($prompt->isDefaultPrompt()) {\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n\n $newPrompt = $this->askAnythingRepository->createPrompt(\n $user,\n $prompt->getTarget(),\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n } elseif ($prompt->getOwnerId() === $user->getId()) {\n $newPrompt = $this->askAnythingRepository->editPrompt(\n $prompt,\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n } else {\n throw new InvalidArgumentException('Edit not allowed for prompt ' . $prompt->getUuid());\n }\n\n return new AskAnythingPromptDto(\n $newPrompt->getUuid(),\n $newPrompt->getTitle(),\n $newPrompt->getContent(),\n $newPrompt->getTarget(),\n $user->getUuid(),\n $shareUsersUuids,\n $shareGroupsUuids,\n $newPrompt->has_reports,\n );\n }\n\n public function delete(\n AskAnythingPrompt $prompt,\n User $user\n ): AskAnythingPrompt {\n if ($prompt->isDefaultPrompt()) {\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n } elseif ($prompt->getOwnerId() === $user->getId()) {\n $userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);\n $userPrompt?->delete();\n // For each relation, re-create the prompt for the receiver as their own\n $this->recreatePromptsForEachRelation($prompt);\n\n // Finally, delete the prompt\n $this->deletePromptIfNoRelations($prompt);\n } else {\n $userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);\n $groupPrompt = $this->askAnythingRepository->findSharedPromptByUserGroup($prompt->getId(), $user);\n\n // If the prompt is shared directly with the user, then \"unshare\" it\n if ($userPrompt instanceof UserAskAnythingPrompt && $groupPrompt === null) {\n $userPrompt->delete();\n $this->deletePromptIfNoRelations($prompt);\n } elseif ($groupPrompt instanceof UserAskAnythingPrompt) {\n // If the prompt is shared with the user and the group, then hide it for this user\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n } else {\n throw new InvalidArgumentException('Unknown delete allowance for prompt ' . $prompt->getUuid());\n }\n }\n\n return $prompt;\n }\n\n public function reorder(\n User $user,\n array $promptUuids,\n ): void {\n foreach ($promptUuids as $index => $promptUuid) {\n $prompt = $this->askAnythingRepository->getPromptByUuid($promptUuid);\n $this->askAnythingRepository->orderPromptForUser($prompt, $user, $index + 1);\n }\n }\n\n /**\n * @param AskAnythingPrompt $prompt\n *\n * @return array[array<string>, array<string>]\n */\n private function getReceiverUuids(AskAnythingPrompt $prompt): array\n {\n $shareUsers = [];\n $shareGroups = [];\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedUser = $sharedPrompt->getUser();\n if ($sharedUser instanceof User && $sharedUser->isStatusActive()) {\n $shareUsers[] = $sharedUser->getUuid();\n }\n $sharedGroup = $sharedPrompt->getGroup();\n if ($sharedGroup instanceof Group) {\n $shareGroups[] = $sharedGroup->getUuid();\n }\n }\n\n return [$shareUsers, $shareGroups];\n }\n\n private function deletePromptIfNoRelations(AskAnythingPrompt $prompt): void\n {\n if ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId())->isEmpty()) {\n // Disable and orphan any AutomatedReports that use this prompt\n $prompt->automatedReports()->withTrashed()->update([\n 'ask_anything_prompt_id' => null,\n 'status' => false,\n ]);\n\n // Delete only if there are no other relations to it.\n $this->askAnythingRepository->deletePrompt($prompt);\n }\n }\n\n private function recreatePromptsForEachRelation(AskAnythingPrompt $prompt): void\n {\n [$sharedUsersIds, $sharedUsersRemovedIds] = $this->recreatePromptsForUserRelations($prompt);\n $this->recreatePromptsForGroupRelations($prompt, $sharedUsersIds, $sharedUsersRemovedIds);\n }\n\n private function recreatePromptsForUserRelations(AskAnythingPrompt $prompt): array\n {\n $sharedUsersIds = [];\n $sharedUsersRemovedIds = [];\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedUser = $sharedPrompt->getUser();\n if ($sharedPrompt->isRemoved() === true) {\n $sharedUsersRemovedIds[] = $sharedUser->getId();\n }\n if ($sharedPrompt->isRemoved() !== true && $sharedUser instanceof User && $sharedUser->isStatusActive()) {\n $sharedUsersIds[] = $sharedUser->getId();\n $this->askAnythingRepository->createPrompt(\n $sharedUser,\n $prompt->getTarget(),\n $prompt->getTitle(),\n $prompt->getContent(),\n [],\n [],\n );\n $sharedPrompt->delete();\n }\n }\n\n return [$sharedUsersIds, $sharedUsersRemovedIds];\n }\n\n private function recreatePromptsForGroupRelations(AskAnythingPrompt $prompt, array $sharedUsersIds, array $sharedUsersRemovedIds): void\n {\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedGroup = $sharedPrompt->getGroup();\n if ($sharedGroup instanceof Group) {\n foreach ($sharedGroup->getMembers() as $member) {\n if (! in_array($member->getId(), $sharedUsersIds)\n && ! in_array($member->getId(), $sharedUsersRemovedIds)) {\n $sharedUsersIds[] = $member->getId();\n $this->askAnythingRepository->createPrompt(\n $member,\n $prompt->getTarget(),\n $prompt->getTitle(),\n $prompt->getContent(),\n [],\n [],\n );\n }\n }\n $sharedPrompt->delete();\n }\n }\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\AskAnything;\n\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\n\nclass AskAnythingPromptService\n{\n public function __construct(\n private readonly AskAnythingRepository $askAnythingRepository,\n private readonly UserRepository $userRepository,\n private readonly GroupRepositoryInterface $groupRepository,\n ) {\n }\n\n /**\n * @return array<AskAnythingPromptDto>\n */\n public function get(User $user, AskAnythingPromptTarget $target): array\n {\n $prompts = $this->askAnythingRepository->findPromptsByUserAndTarget(\n $user,\n $target\n );\n\n $promptDtos = [];\n foreach ($prompts as $prompt) {\n $ownerUuid = null;\n if ($prompt->getOwner() !== null) {\n $ownerUuid = $prompt->getOwner()->getUuid();\n }\n $shareUsers = null;\n $shareGroups = null;\n\n // Provide users and groups only if owner of the prompt is current user\n if ($prompt->getOwnerId() === $user->getId()) {\n [$shareUsers, $shareGroups] = $this->getReceiverUuids($prompt);\n }\n\n $promptDtos[] = new AskAnythingPromptDto(\n $prompt->getUuid(),\n $prompt->getTitle(),\n $prompt->getContent(),\n $target,\n $ownerUuid,\n $shareUsers,\n $shareGroups,\n $prompt->getHasReports(),\n );\n }\n\n return $promptDtos;\n }\n\n /**\n * @param array<string> $shareUsersUuids\n * @param array<string> $shareGroupsUuids\n */\n public function create(\n User $user,\n string $title,\n string $content,\n AskAnythingPromptTarget $target,\n array $shareUsersUuids,\n array $shareGroupsUuids\n ): AskAnythingPromptDto {\n\n $shareUsers = $shareGroups = [];\n foreach ($shareUsersUuids as $userUuid) {\n $shareUsers[] = $this->userRepository->findByUuid($userUuid);\n }\n foreach ($shareGroupsUuids as $groupUuid) {\n $shareGroups[] = $this->groupRepository->findByUuid($groupUuid);\n }\n\n $prompt = $this->askAnythingRepository->createPrompt(\n $user,\n $target,\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n\n return new AskAnythingPromptDto(\n $prompt->getUuid(),\n $prompt->getTitle(),\n $prompt->getContent(),\n $target,\n $user->getUuid(),\n $shareUsersUuids,\n $shareGroupsUuids,\n $prompt->has_reports,\n );\n }\n\n /**\n * @param array<string> $shareUsersUuids\n * @param array<string> $shareGroupsUuids\n *\n * @throws InvalidArgumentException\n */\n public function edit(\n AskAnythingPrompt $prompt,\n User $user,\n string $title,\n string $content,\n array $shareUsersUuids,\n array $shareGroupsUuids\n ): AskAnythingPromptDto {\n $shareUsers = $shareGroups = [];\n foreach ($shareUsersUuids as $userUuid) {\n $shareUsers[] = $this->userRepository->findByUuid($userUuid);\n }\n foreach ($shareGroupsUuids as $groupUuid) {\n $shareGroups[] = $this->groupRepository->findByUuid($groupUuid);\n }\n\n if ($prompt->isDefaultPrompt()) {\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n\n $newPrompt = $this->askAnythingRepository->createPrompt(\n $user,\n $prompt->getTarget(),\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n } elseif ($prompt->getOwnerId() === $user->getId()) {\n $newPrompt = $this->askAnythingRepository->editPrompt(\n $prompt,\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n } else {\n throw new InvalidArgumentException('Edit not allowed for prompt ' . $prompt->getUuid());\n }\n\n return new AskAnythingPromptDto(\n $newPrompt->getUuid(),\n $newPrompt->getTitle(),\n $newPrompt->getContent(),\n $newPrompt->getTarget(),\n $user->getUuid(),\n $shareUsersUuids,\n $shareGroupsUuids,\n $newPrompt->has_reports,\n );\n }\n\n public function delete(\n AskAnythingPrompt $prompt,\n User $user\n ): AskAnythingPrompt {\n if ($prompt->isDefaultPrompt()) {\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n } elseif ($prompt->getOwnerId() === $user->getId()) {\n $userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);\n $userPrompt?->delete();\n // For each relation, re-create the prompt for the receiver as their own\n $this->recreatePromptsForEachRelation($prompt);\n\n // Finally, delete the prompt\n $this->deletePromptIfNoRelations($prompt);\n } else {\n $userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);\n $groupPrompt = $this->askAnythingRepository->findSharedPromptByUserGroup($prompt->getId(), $user);\n\n // If the prompt is shared directly with the user, then \"unshare\" it\n if ($userPrompt instanceof UserAskAnythingPrompt && $groupPrompt === null) {\n $userPrompt->delete();\n $this->deletePromptIfNoRelations($prompt);\n } elseif ($groupPrompt instanceof UserAskAnythingPrompt) {\n // If the prompt is shared with the user and the group, then hide it for this user\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n } else {\n throw new InvalidArgumentException('Unknown delete allowance for prompt ' . $prompt->getUuid());\n }\n }\n\n return $prompt;\n }\n\n public function reorder(\n User $user,\n array $promptUuids,\n ): void {\n foreach ($promptUuids as $index => $promptUuid) {\n $prompt = $this->askAnythingRepository->getPromptByUuid($promptUuid);\n $this->askAnythingRepository->orderPromptForUser($prompt, $user, $index + 1);\n }\n }\n\n /**\n * @param AskAnythingPrompt $prompt\n *\n * @return array[array<string>, array<string>]\n */\n private function getReceiverUuids(AskAnythingPrompt $prompt): array\n {\n $shareUsers = [];\n $shareGroups = [];\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedUser = $sharedPrompt->getUser();\n if ($sharedUser instanceof User && $sharedUser->isStatusActive()) {\n $shareUsers[] = $sharedUser->getUuid();\n }\n $sharedGroup = $sharedPrompt->getGroup();\n if ($sharedGroup instanceof Group) {\n $shareGroups[] = $sharedGroup->getUuid();\n }\n }\n\n return [$shareUsers, $shareGroups];\n }\n\n private function deletePromptIfNoRelations(AskAnythingPrompt $prompt): void\n {\n if ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId())->isEmpty()) {\n // Disable and orphan any AutomatedReports that use this prompt\n $prompt->automatedReports()->withTrashed()->update([\n 'ask_anything_prompt_id' => null,\n 'status' => false,\n ]);\n\n // Delete only if there are no other relations to it.\n $this->askAnythingRepository->deletePrompt($prompt);\n }\n }\n\n private function recreatePromptsForEachRelation(AskAnythingPrompt $prompt): void\n {\n [$sharedUsersIds, $sharedUsersRemovedIds] = $this->recreatePromptsForUserRelations($prompt);\n $this->recreatePromptsForGroupRelations($prompt, $sharedUsersIds, $sharedUsersRemovedIds);\n }\n\n private function recreatePromptsForUserRelations(AskAnythingPrompt $prompt): array\n {\n $sharedUsersIds = [];\n $sharedUsersRemovedIds = [];\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedUser = $sharedPrompt->getUser();\n if ($sharedPrompt->isRemoved() === true) {\n $sharedUsersRemovedIds[] = $sharedUser->getId();\n }\n if ($sharedPrompt->isRemoved() !== true && $sharedUser instanceof User && $sharedUser->isStatusActive()) {\n $sharedUsersIds[] = $sharedUser->getId();\n $this->askAnythingRepository->createPrompt(\n $sharedUser,\n $prompt->getTarget(),\n $prompt->getTitle(),\n $prompt->getContent(),\n [],\n [],\n );\n $sharedPrompt->delete();\n }\n }\n\n return [$sharedUsersIds, $sharedUsersRemovedIds];\n }\n\n private function recreatePromptsForGroupRelations(AskAnythingPrompt $prompt, array $sharedUsersIds, array $sharedUsersRemovedIds): void\n {\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedGroup = $sharedPrompt->getGroup();\n if ($sharedGroup instanceof Group) {\n foreach ($sharedGroup->getMembers() as $member) {\n if (! in_array($member->getId(), $sharedUsersIds)\n && ! in_array($member->getId(), $sharedUsersRemovedIds)) {\n $sharedUsersIds[] = $member->getId();\n $this->askAnythingRepository->createPrompt(\n $member,\n $prompt->getTarget(),\n $prompt->getTitle(),\n $prompt->getContent(),\n [],\n [],\n );\n }\n }\n $sharedPrompt->delete();\n }\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
8246594430560437790
|
1126917008115010046
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\AskAnything;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
class AskAnythingPromptService
{
public function __construct(
private readonly AskAnythingRepository $askAnythingRepository,
private readonly UserRepository $userRepository,
private readonly GroupRepositoryInterface $groupRepository,
) {
}
/**
* @return array<AskAnythingPromptDto>
*/
public function get(User $user, AskAnythingPromptTarget $target): array
{
$prompts = $this->askAnythingRepository->findPromptsByUserAndTarget(
$user,
$target
);
$promptDtos = [];
foreach ($prompts as $prompt) {
$ownerUuid = null;
if ($prompt->getOwner() !== null) {
$ownerUuid = $prompt->getOwner()->getUuid();
}
$shareUsers = null;
$shareGroups = null;
// Provide users and groups only if owner of the prompt is current user
if ($prompt->getOwnerId() === $user->getId()) {
[$shareUsers, $shareGroups] = $this->getReceiverUuids($prompt);
}
$promptDtos[] = new AskAnythingPromptDto(
$prompt->getUuid(),
$prompt->getTitle(),
$prompt->getContent(),
$target,
$ownerUuid,
$shareUsers,
$shareGroups,
$prompt->getHasReports(),
);
}
return $promptDtos;
}
/**
* @param array<string> $shareUsersUuids
* @param array<string> $shareGroupsUuids
*/
public function create(
User $user,
string $title,
string $content,
AskAnythingPromptTarget $target,
array $shareUsersUuids,
array $shareGroupsUuids
): AskAnythingPromptDto {
$shareUsers = $shareGroups = [];
foreach ($shareUsersUuids as $userUuid) {
$shareUsers[] = $this->userRepository->findByUuid($userUuid);
}
foreach ($shareGroupsUuids as $groupUuid) {
$shareGroups[] = $this->groupRepository->findByUuid($groupUuid);
}
$prompt = $this->askAnythingRepository->createPrompt(
$user,
$target,
$title,
$content,
$shareUsers,
$shareGroups,
);
return new AskAnythingPromptDto(
$prompt->getUuid(),
$prompt->getTitle(),
$prompt->getContent(),
$target,
$user->getUuid(),
$shareUsersUuids,
$shareGroupsUuids,
$prompt->has_reports,
);
}
/**
* @param array<string> $shareUsersUuids
* @param array<string> $shareGroupsUuids
*
* @throws InvalidArgumentException
*/
public function edit(
AskAnythingPrompt $prompt,
User $user,
string $title,
string $content,
array $shareUsersUuids,
array $shareGroupsUuids
): AskAnythingPromptDto {
$shareUsers = $shareGroups = [];
foreach ($shareUsersUuids as $userUuid) {
$shareUsers[] = $this->userRepository->findByUuid($userUuid);
}
foreach ($shareGroupsUuids as $groupUuid) {
$shareGroups[] = $this->groupRepository->findByUuid($groupUuid);
}
if ($prompt->isDefaultPrompt()) {
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
$newPrompt = $this->askAnythingRepository->createPrompt(
$user,
$prompt->getTarget(),
$title,
$content,
$shareUsers,
$shareGroups,
);
} elseif ($prompt->getOwnerId() === $user->getId()) {
$newPrompt = $this->askAnythingRepository->editPrompt(
$prompt,
$title,
$content,
$shareUsers,
$shareGroups,
);
} else {
throw new InvalidArgumentException('Edit not allowed for prompt ' . $prompt->getUuid());
}
return new AskAnythingPromptDto(
$newPrompt->getUuid(),
$newPrompt->getTitle(),
$newPrompt->getContent(),
$newPrompt->getTarget(),
$user->getUuid(),
$shareUsersUuids,
$shareGroupsUuids,
$newPrompt->has_reports,
);
}
public function delete(
AskAnythingPrompt $prompt,
User $user
): AskAnythingPrompt {
if ($prompt->isDefaultPrompt()) {
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
} elseif ($prompt->getOwnerId() === $user->getId()) {
$userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);
$userPrompt?->delete();
// For each relation, re-create the prompt for the receiver as their own
$this->recreatePromptsForEachRelation($prompt);
// Finally, delete the prompt
$this->deletePromptIfNoRelations($prompt);
} else {
$userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);
$groupPrompt = $this->askAnythingRepository->findSharedPromptByUserGroup($prompt->getId(), $user);
// If the prompt is shared directly with the user, then "unshare" it
if ($userPrompt instanceof UserAskAnythingPrompt && $groupPrompt === null) {
$userPrompt->delete();
$this->deletePromptIfNoRelations($prompt);
} elseif ($groupPrompt instanceof UserAskAnythingPrompt) {
// If the prompt is shared with the user and the group, then hide it for this user
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
} else {
throw new InvalidArgumentException('Unknown delete allowance for prompt ' . $prompt->getUuid());
}
}
return $prompt;
}
public function reorder(
User $user,
array $promptUuids,
): void {
foreach ($promptUuids as $index => $promptUuid) {
$prompt = $this->askAnythingRepository->getPromptByUuid($promptUuid);
$this->askAnythingRepository->orderPromptForUser($prompt, $user, $index + 1);
}
}
/**
* @param AskAnythingPrompt $prompt
*
* @return array[array<string>, array<string>]
*/
private function getReceiverUuids(AskAnythingPrompt $prompt): array
{
$shareUsers = [];
$shareGroups = [];
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedUser = $sharedPrompt->getUser();
if ($sharedUser instanceof User && $sharedUser->isStatusActive()) {
$shareUsers[] = $sharedUser->getUuid();
}
$sharedGroup = $sharedPrompt->getGroup();
if ($sharedGroup instanceof Group) {
$shareGroups[] = $sharedGroup->getUuid();
}
}
return [$shareUsers, $shareGroups];
}
private function deletePromptIfNoRelations(AskAnythingPrompt $prompt): void
{
if ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId())->isEmpty()) {
// Disable and orphan any AutomatedReports that use this prompt
$prompt->automatedReports()->withTrashed()->update([
'ask_anything_prompt_id' => null,
'status' => false,
]);
// Delete only if there are no other relations to it.
$this->askAnythingRepository->deletePrompt($prompt);
}
}
private function recreatePromptsForEachRelation(AskAnythingPrompt $prompt): void
{
[$sharedUsersIds, $sharedUsersRemovedIds] = $this->recreatePromptsForUserRelations($prompt);
$this->recreatePromptsForGroupRelations($prompt, $sharedUsersIds, $sharedUsersRemovedIds);
}
private function recreatePromptsForUserRelations(AskAnythingPrompt $prompt): array
{
$sharedUsersIds = [];
$sharedUsersRemovedIds = [];
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedUser = $sharedPrompt->getUser();
if ($sharedPrompt->isRemoved() === true) {
$sharedUsersRemovedIds[] = $sharedUser->getId();
}
if ($sharedPrompt->isRemoved() !== true && $sharedUser instanceof User && $sharedUser->isStatusActive()) {
$sharedUsersIds[] = $sharedUser->getId();
$this->askAnythingRepository->createPrompt(
$sharedUser,
$prompt->getTarget(),
$prompt->getTitle(),
$prompt->getContent(),
[],
[],
);
$sharedPrompt->delete();
}
}
return [$sharedUsersIds, $sharedUsersRemovedIds];
}
private function recreatePromptsForGroupRelations(AskAnythingPrompt $prompt, array $sharedUsersIds, array $sharedUsersRemovedIds): void
{
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedGroup = $sharedPrompt->getGroup();
if ($sharedGroup instanceof Group) {
foreach ($sharedGroup->getMembers() as $member) {
if (! in_array($member->getId(), $sharedUsersIds)
&& ! in_array($member->getId(), $sharedUsersRemovedIds)) {
$sharedUsersIds[] = $member->getId();
$this->askAnythingRepository->createPrompt(
$member,
$prompt->getTarget(),
$prompt->getTitle(),
$prompt->getContent(),
[],
[],
);
}
}
$sharedPrompt->delete();
}
}
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
56821
|
1974
|
7
|
2026-05-19T08:26:43.979199+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179203979_m1.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\AskAnything;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
class AskAnythingPromptService
{
public function __construct(
private readonly AskAnythingRepository $askAnythingRepository,
private readonly UserRepository $userRepository,
private readonly GroupRepositoryInterface $groupRepository,
) {
}
/**
* @return array<AskAnythingPromptDto>
*/
public function get(User $user, AskAnythingPromptTarget $target): array
{
$prompts = $this->askAnythingRepository->findPromptsByUserAndTarget(
$user,
$target
);
$promptDtos = [];
foreach ($prompts as $prompt) {
$ownerUuid = null;
if ($prompt->getOwner() !== null) {
$ownerUuid = $prompt->getOwner()->getUuid();
}
$shareUsers = null;
$shareGroups = null;
// Provide users and groups only if owner of the prompt is current user
if ($prompt->getOwnerId() === $user->getId()) {
[$shareUsers, $shareGroups] = $this->getReceiverUuids($prompt);
}
$promptDtos[] = new AskAnythingPromptDto(
$prompt->getUuid(),
$prompt->getTitle(),
$prompt->getContent(),
$target,
$ownerUuid,
$shareUsers,
$shareGroups,
$prompt->getHasReports(),
);
}
return $promptDtos;
}
/**
* @param array<string> $shareUsersUuids
* @param array<string> $shareGroupsUuids
*/
public function create(
User $user,
string $title,
string $content,
AskAnythingPromptTarget $target,
array $shareUsersUuids,
array $shareGroupsUuids
): AskAnythingPromptDto {
$shareUsers = $shareGroups = [];
foreach ($shareUsersUuids as $userUuid) {
$shareUsers[] = $this->userRepository->findByUuid($userUuid);
}
foreach ($shareGroupsUuids as $groupUuid) {
$shareGroups[] = $this->groupRepository->findByUuid($groupUuid);
}
$prompt = $this->askAnythingRepository->createPrompt(
$user,
$target,
$title,
$content,
$shareUsers,
$shareGroups,
);
return new AskAnythingPromptDto(
$prompt->getUuid(),
$prompt->getTitle(),
$prompt->getContent(),
$target,
$user->getUuid(),
$shareUsersUuids,
$shareGroupsUuids,
$prompt->has_reports,
);
}
/**
* @param array<string> $shareUsersUuids
* @param array<string> $shareGroupsUuids
*
* @throws InvalidArgumentException
*/
public function edit(
AskAnythingPrompt $prompt,
User $user,
string $title,
string $content,
array $shareUsersUuids,
array $shareGroupsUuids
): AskAnythingPromptDto {
$shareUsers = $shareGroups = [];
foreach ($shareUsersUuids as $userUuid) {
$shareUsers[] = $this->userRepository->findByUuid($userUuid);
}
foreach ($shareGroupsUuids as $groupUuid) {
$shareGroups[] = $this->groupRepository->findByUuid($groupUuid);
}
if ($prompt->isDefaultPrompt()) {
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
$newPrompt = $this->askAnythingRepository->createPrompt(
$user,
$prompt->getTarget(),
$title,
$content,
$shareUsers,
$shareGroups,
);
} elseif ($prompt->getOwnerId() === $user->getId()) {
$newPrompt = $this->askAnythingRepository->editPrompt(
$prompt,
$title,
$content,
$shareUsers,
$shareGroups,
);
} else {
throw new InvalidArgumentException('Edit not allowed for prompt ' . $prompt->getUuid());
}
return new AskAnythingPromptDto(
$newPrompt->getUuid(),
$newPrompt->getTitle(),
$newPrompt->getContent(),
$newPrompt->getTarget(),
$user->getUuid(),
$shareUsersUuids,
$shareGroupsUuids,
$newPrompt->has_reports,
);
}
public function delete(
AskAnythingPrompt $prompt,
User $user
): AskAnythingPrompt {
if ($prompt->isDefaultPrompt()) {
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
} elseif ($prompt->getOwnerId() === $user->getId()) {
$userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);
$userPrompt?->delete();
// For each relation, re-create the prompt for the receiver as their own
$this->recreatePromptsForEachRelation($prompt);
// Finally, delete the prompt
$this->deletePromptIfNoRelations($prompt);
} else {
$userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);
$groupPrompt = $this->askAnythingRepository->findSharedPromptByUserGroup($prompt->getId(), $user);
// If the prompt is shared directly with the user, then "unshare" it
if ($userPrompt instanceof UserAskAnythingPrompt && $groupPrompt === null) {
$userPrompt->delete();
$this->deletePromptIfNoRelations($prompt);
} elseif ($groupPrompt instanceof UserAskAnythingPrompt) {
// If the prompt is shared with the user and the group, then hide it for this user
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
} else {
throw new InvalidArgumentException('Unknown delete allowance for prompt ' . $prompt->getUuid());
}
}
return $prompt;
}
public function reorder(
User $user,
array $promptUuids,
): void {
foreach ($promptUuids as $index => $promptUuid) {
$prompt = $this->askAnythingRepository->getPromptByUuid($promptUuid);
$this->askAnythingRepository->orderPromptForUser($prompt, $user, $index + 1);
}
}
/**
* @param AskAnythingPrompt $prompt
*
* @return array[array<string>, array<string>]
*/
private function getReceiverUuids(AskAnythingPrompt $prompt): array
{
$shareUsers = [];
$shareGroups = [];
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedUser = $sharedPrompt->getUser();
if ($sharedUser instanceof User && $sharedUser->isStatusActive()) {
$shareUsers[] = $sharedUser->getUuid();
}
$sharedGroup = $sharedPrompt->getGroup();
if ($sharedGroup instanceof Group) {
$shareGroups[] = $sharedGroup->getUuid();
}
}
return [$shareUsers, $shareGroups];
}
private function deletePromptIfNoRelations(AskAnythingPrompt $prompt): void
{
if ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId())->isEmpty()) {
// Disable and orphan any AutomatedReports that use this prompt
$prompt->automatedReports()->withTrashed()->update([
'ask_anything_prompt_id' => null,
'status' => false,
]);
// Delete only if there are no other relations to it.
$this->askAnythingRepository->deletePrompt($prompt);
}
}
private function recreatePromptsForEachRelation(AskAnythingPrompt $prompt): void
{
[$sharedUsersIds, $sharedUsersRemovedIds] = $this->recreatePromptsForUserRelations($prompt);
$this->recreatePromptsForGroupRelations($prompt, $sharedUsersIds, $sharedUsersRemovedIds);
}
private function recreatePromptsForUserRelations(AskAnythingPrompt $prompt): array
{
$sharedUsersIds = [];
$sharedUsersRemovedIds = [];
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedUser = $sharedPrompt->getUser();
if ($sharedPrompt->isRemoved() === true) {
$sharedUsersRemovedIds[] = $sharedUser->getId();
}
if ($sharedPrompt->isRemoved() !== true && $sharedUser instanceof User && $sharedUser->isStatusActive()) {
$sharedUsersIds[] = $sharedUser->getId();
$this->askAnythingRepository->createPrompt(
$sharedUser,
$prompt->getTarget(),
$prompt->getTitle(),
$prompt->getContent(),
[],
[],
);
$sharedPrompt->delete();
}
}
return [$sharedUsersIds, $sharedUsersRemovedIds];
}
private function recreatePromptsForGroupRelations(AskAnythingPrompt $prompt, array $sharedUsersIds, array $sharedUsersRemovedIds): void
{
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedGroup = $sharedPrompt->getGroup();
if ($sharedGroup instanceof Group) {
foreach ($sharedGroup->getMembers() as $member) {
if (! in_array($member->getId(), $sharedUsersIds)
&& ! in_array($member->getId(), $sharedUsersRemovedIds)) {
$sharedUsersIds[] = $member->getId();
$this->askAnythingRepository->createPrompt(
$member,
$prompt->getTarget(),
$prompt->getTitle(),
$prompt->getContent(),
[],
[],
);
}
}
$sharedPrompt->delete();
}
}
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"4","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.016666668,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.016666668,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\AskAnything;\n\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\n\nclass AskAnythingPromptService\n{\n public function __construct(\n private readonly AskAnythingRepository $askAnythingRepository,\n private readonly UserRepository $userRepository,\n private readonly GroupRepositoryInterface $groupRepository,\n ) {\n }\n\n /**\n * @return array<AskAnythingPromptDto>\n */\n public function get(User $user, AskAnythingPromptTarget $target): array\n {\n $prompts = $this->askAnythingRepository->findPromptsByUserAndTarget(\n $user,\n $target\n );\n\n $promptDtos = [];\n foreach ($prompts as $prompt) {\n $ownerUuid = null;\n if ($prompt->getOwner() !== null) {\n $ownerUuid = $prompt->getOwner()->getUuid();\n }\n $shareUsers = null;\n $shareGroups = null;\n\n // Provide users and groups only if owner of the prompt is current user\n if ($prompt->getOwnerId() === $user->getId()) {\n [$shareUsers, $shareGroups] = $this->getReceiverUuids($prompt);\n }\n\n $promptDtos[] = new AskAnythingPromptDto(\n $prompt->getUuid(),\n $prompt->getTitle(),\n $prompt->getContent(),\n $target,\n $ownerUuid,\n $shareUsers,\n $shareGroups,\n $prompt->getHasReports(),\n );\n }\n\n return $promptDtos;\n }\n\n /**\n * @param array<string> $shareUsersUuids\n * @param array<string> $shareGroupsUuids\n */\n public function create(\n User $user,\n string $title,\n string $content,\n AskAnythingPromptTarget $target,\n array $shareUsersUuids,\n array $shareGroupsUuids\n ): AskAnythingPromptDto {\n\n $shareUsers = $shareGroups = [];\n foreach ($shareUsersUuids as $userUuid) {\n $shareUsers[] = $this->userRepository->findByUuid($userUuid);\n }\n foreach ($shareGroupsUuids as $groupUuid) {\n $shareGroups[] = $this->groupRepository->findByUuid($groupUuid);\n }\n\n $prompt = $this->askAnythingRepository->createPrompt(\n $user,\n $target,\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n\n return new AskAnythingPromptDto(\n $prompt->getUuid(),\n $prompt->getTitle(),\n $prompt->getContent(),\n $target,\n $user->getUuid(),\n $shareUsersUuids,\n $shareGroupsUuids,\n $prompt->has_reports,\n );\n }\n\n /**\n * @param array<string> $shareUsersUuids\n * @param array<string> $shareGroupsUuids\n *\n * @throws InvalidArgumentException\n */\n public function edit(\n AskAnythingPrompt $prompt,\n User $user,\n string $title,\n string $content,\n array $shareUsersUuids,\n array $shareGroupsUuids\n ): AskAnythingPromptDto {\n $shareUsers = $shareGroups = [];\n foreach ($shareUsersUuids as $userUuid) {\n $shareUsers[] = $this->userRepository->findByUuid($userUuid);\n }\n foreach ($shareGroupsUuids as $groupUuid) {\n $shareGroups[] = $this->groupRepository->findByUuid($groupUuid);\n }\n\n if ($prompt->isDefaultPrompt()) {\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n\n $newPrompt = $this->askAnythingRepository->createPrompt(\n $user,\n $prompt->getTarget(),\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n } elseif ($prompt->getOwnerId() === $user->getId()) {\n $newPrompt = $this->askAnythingRepository->editPrompt(\n $prompt,\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n } else {\n throw new InvalidArgumentException('Edit not allowed for prompt ' . $prompt->getUuid());\n }\n\n return new AskAnythingPromptDto(\n $newPrompt->getUuid(),\n $newPrompt->getTitle(),\n $newPrompt->getContent(),\n $newPrompt->getTarget(),\n $user->getUuid(),\n $shareUsersUuids,\n $shareGroupsUuids,\n $newPrompt->has_reports,\n );\n }\n\n public function delete(\n AskAnythingPrompt $prompt,\n User $user\n ): AskAnythingPrompt {\n if ($prompt->isDefaultPrompt()) {\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n } elseif ($prompt->getOwnerId() === $user->getId()) {\n $userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);\n $userPrompt?->delete();\n // For each relation, re-create the prompt for the receiver as their own\n $this->recreatePromptsForEachRelation($prompt);\n\n // Finally, delete the prompt\n $this->deletePromptIfNoRelations($prompt);\n } else {\n $userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);\n $groupPrompt = $this->askAnythingRepository->findSharedPromptByUserGroup($prompt->getId(), $user);\n\n // If the prompt is shared directly with the user, then \"unshare\" it\n if ($userPrompt instanceof UserAskAnythingPrompt && $groupPrompt === null) {\n $userPrompt->delete();\n $this->deletePromptIfNoRelations($prompt);\n } elseif ($groupPrompt instanceof UserAskAnythingPrompt) {\n // If the prompt is shared with the user and the group, then hide it for this user\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n } else {\n throw new InvalidArgumentException('Unknown delete allowance for prompt ' . $prompt->getUuid());\n }\n }\n\n return $prompt;\n }\n\n public function reorder(\n User $user,\n array $promptUuids,\n ): void {\n foreach ($promptUuids as $index => $promptUuid) {\n $prompt = $this->askAnythingRepository->getPromptByUuid($promptUuid);\n $this->askAnythingRepository->orderPromptForUser($prompt, $user, $index + 1);\n }\n }\n\n /**\n * @param AskAnythingPrompt $prompt\n *\n * @return array[array<string>, array<string>]\n */\n private function getReceiverUuids(AskAnythingPrompt $prompt): array\n {\n $shareUsers = [];\n $shareGroups = [];\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedUser = $sharedPrompt->getUser();\n if ($sharedUser instanceof User && $sharedUser->isStatusActive()) {\n $shareUsers[] = $sharedUser->getUuid();\n }\n $sharedGroup = $sharedPrompt->getGroup();\n if ($sharedGroup instanceof Group) {\n $shareGroups[] = $sharedGroup->getUuid();\n }\n }\n\n return [$shareUsers, $shareGroups];\n }\n\n private function deletePromptIfNoRelations(AskAnythingPrompt $prompt): void\n {\n if ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId())->isEmpty()) {\n // Disable and orphan any AutomatedReports that use this prompt\n $prompt->automatedReports()->withTrashed()->update([\n 'ask_anything_prompt_id' => null,\n 'status' => false,\n ]);\n\n // Delete only if there are no other relations to it.\n $this->askAnythingRepository->deletePrompt($prompt);\n }\n }\n\n private function recreatePromptsForEachRelation(AskAnythingPrompt $prompt): void\n {\n [$sharedUsersIds, $sharedUsersRemovedIds] = $this->recreatePromptsForUserRelations($prompt);\n $this->recreatePromptsForGroupRelations($prompt, $sharedUsersIds, $sharedUsersRemovedIds);\n }\n\n private function recreatePromptsForUserRelations(AskAnythingPrompt $prompt): array\n {\n $sharedUsersIds = [];\n $sharedUsersRemovedIds = [];\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedUser = $sharedPrompt->getUser();\n if ($sharedPrompt->isRemoved() === true) {\n $sharedUsersRemovedIds[] = $sharedUser->getId();\n }\n if ($sharedPrompt->isRemoved() !== true && $sharedUser instanceof User && $sharedUser->isStatusActive()) {\n $sharedUsersIds[] = $sharedUser->getId();\n $this->askAnythingRepository->createPrompt(\n $sharedUser,\n $prompt->getTarget(),\n $prompt->getTitle(),\n $prompt->getContent(),\n [],\n [],\n );\n $sharedPrompt->delete();\n }\n }\n\n return [$sharedUsersIds, $sharedUsersRemovedIds];\n }\n\n private function recreatePromptsForGroupRelations(AskAnythingPrompt $prompt, array $sharedUsersIds, array $sharedUsersRemovedIds): void\n {\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedGroup = $sharedPrompt->getGroup();\n if ($sharedGroup instanceof Group) {\n foreach ($sharedGroup->getMembers() as $member) {\n if (! in_array($member->getId(), $sharedUsersIds)\n && ! in_array($member->getId(), $sharedUsersRemovedIds)) {\n $sharedUsersIds[] = $member->getId();\n $this->askAnythingRepository->createPrompt(\n $member,\n $prompt->getTarget(),\n $prompt->getTitle(),\n $prompt->getContent(),\n [],\n [],\n );\n }\n }\n $sharedPrompt->delete();\n }\n }\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\AskAnything;\n\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\n\nclass AskAnythingPromptService\n{\n public function __construct(\n private readonly AskAnythingRepository $askAnythingRepository,\n private readonly UserRepository $userRepository,\n private readonly GroupRepositoryInterface $groupRepository,\n ) {\n }\n\n /**\n * @return array<AskAnythingPromptDto>\n */\n public function get(User $user, AskAnythingPromptTarget $target): array\n {\n $prompts = $this->askAnythingRepository->findPromptsByUserAndTarget(\n $user,\n $target\n );\n\n $promptDtos = [];\n foreach ($prompts as $prompt) {\n $ownerUuid = null;\n if ($prompt->getOwner() !== null) {\n $ownerUuid = $prompt->getOwner()->getUuid();\n }\n $shareUsers = null;\n $shareGroups = null;\n\n // Provide users and groups only if owner of the prompt is current user\n if ($prompt->getOwnerId() === $user->getId()) {\n [$shareUsers, $shareGroups] = $this->getReceiverUuids($prompt);\n }\n\n $promptDtos[] = new AskAnythingPromptDto(\n $prompt->getUuid(),\n $prompt->getTitle(),\n $prompt->getContent(),\n $target,\n $ownerUuid,\n $shareUsers,\n $shareGroups,\n $prompt->getHasReports(),\n );\n }\n\n return $promptDtos;\n }\n\n /**\n * @param array<string> $shareUsersUuids\n * @param array<string> $shareGroupsUuids\n */\n public function create(\n User $user,\n string $title,\n string $content,\n AskAnythingPromptTarget $target,\n array $shareUsersUuids,\n array $shareGroupsUuids\n ): AskAnythingPromptDto {\n\n $shareUsers = $shareGroups = [];\n foreach ($shareUsersUuids as $userUuid) {\n $shareUsers[] = $this->userRepository->findByUuid($userUuid);\n }\n foreach ($shareGroupsUuids as $groupUuid) {\n $shareGroups[] = $this->groupRepository->findByUuid($groupUuid);\n }\n\n $prompt = $this->askAnythingRepository->createPrompt(\n $user,\n $target,\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n\n return new AskAnythingPromptDto(\n $prompt->getUuid(),\n $prompt->getTitle(),\n $prompt->getContent(),\n $target,\n $user->getUuid(),\n $shareUsersUuids,\n $shareGroupsUuids,\n $prompt->has_reports,\n );\n }\n\n /**\n * @param array<string> $shareUsersUuids\n * @param array<string> $shareGroupsUuids\n *\n * @throws InvalidArgumentException\n */\n public function edit(\n AskAnythingPrompt $prompt,\n User $user,\n string $title,\n string $content,\n array $shareUsersUuids,\n array $shareGroupsUuids\n ): AskAnythingPromptDto {\n $shareUsers = $shareGroups = [];\n foreach ($shareUsersUuids as $userUuid) {\n $shareUsers[] = $this->userRepository->findByUuid($userUuid);\n }\n foreach ($shareGroupsUuids as $groupUuid) {\n $shareGroups[] = $this->groupRepository->findByUuid($groupUuid);\n }\n\n if ($prompt->isDefaultPrompt()) {\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n\n $newPrompt = $this->askAnythingRepository->createPrompt(\n $user,\n $prompt->getTarget(),\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n } elseif ($prompt->getOwnerId() === $user->getId()) {\n $newPrompt = $this->askAnythingRepository->editPrompt(\n $prompt,\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n } else {\n throw new InvalidArgumentException('Edit not allowed for prompt ' . $prompt->getUuid());\n }\n\n return new AskAnythingPromptDto(\n $newPrompt->getUuid(),\n $newPrompt->getTitle(),\n $newPrompt->getContent(),\n $newPrompt->getTarget(),\n $user->getUuid(),\n $shareUsersUuids,\n $shareGroupsUuids,\n $newPrompt->has_reports,\n );\n }\n\n public function delete(\n AskAnythingPrompt $prompt,\n User $user\n ): AskAnythingPrompt {\n if ($prompt->isDefaultPrompt()) {\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n } elseif ($prompt->getOwnerId() === $user->getId()) {\n $userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);\n $userPrompt?->delete();\n // For each relation, re-create the prompt for the receiver as their own\n $this->recreatePromptsForEachRelation($prompt);\n\n // Finally, delete the prompt\n $this->deletePromptIfNoRelations($prompt);\n } else {\n $userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);\n $groupPrompt = $this->askAnythingRepository->findSharedPromptByUserGroup($prompt->getId(), $user);\n\n // If the prompt is shared directly with the user, then \"unshare\" it\n if ($userPrompt instanceof UserAskAnythingPrompt && $groupPrompt === null) {\n $userPrompt->delete();\n $this->deletePromptIfNoRelations($prompt);\n } elseif ($groupPrompt instanceof UserAskAnythingPrompt) {\n // If the prompt is shared with the user and the group, then hide it for this user\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n } else {\n throw new InvalidArgumentException('Unknown delete allowance for prompt ' . $prompt->getUuid());\n }\n }\n\n return $prompt;\n }\n\n public function reorder(\n User $user,\n array $promptUuids,\n ): void {\n foreach ($promptUuids as $index => $promptUuid) {\n $prompt = $this->askAnythingRepository->getPromptByUuid($promptUuid);\n $this->askAnythingRepository->orderPromptForUser($prompt, $user, $index + 1);\n }\n }\n\n /**\n * @param AskAnythingPrompt $prompt\n *\n * @return array[array<string>, array<string>]\n */\n private function getReceiverUuids(AskAnythingPrompt $prompt): array\n {\n $shareUsers = [];\n $shareGroups = [];\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedUser = $sharedPrompt->getUser();\n if ($sharedUser instanceof User && $sharedUser->isStatusActive()) {\n $shareUsers[] = $sharedUser->getUuid();\n }\n $sharedGroup = $sharedPrompt->getGroup();\n if ($sharedGroup instanceof Group) {\n $shareGroups[] = $sharedGroup->getUuid();\n }\n }\n\n return [$shareUsers, $shareGroups];\n }\n\n private function deletePromptIfNoRelations(AskAnythingPrompt $prompt): void\n {\n if ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId())->isEmpty()) {\n // Disable and orphan any AutomatedReports that use this prompt\n $prompt->automatedReports()->withTrashed()->update([\n 'ask_anything_prompt_id' => null,\n 'status' => false,\n ]);\n\n // Delete only if there are no other relations to it.\n $this->askAnythingRepository->deletePrompt($prompt);\n }\n }\n\n private function recreatePromptsForEachRelation(AskAnythingPrompt $prompt): void\n {\n [$sharedUsersIds, $sharedUsersRemovedIds] = $this->recreatePromptsForUserRelations($prompt);\n $this->recreatePromptsForGroupRelations($prompt, $sharedUsersIds, $sharedUsersRemovedIds);\n }\n\n private function recreatePromptsForUserRelations(AskAnythingPrompt $prompt): array\n {\n $sharedUsersIds = [];\n $sharedUsersRemovedIds = [];\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedUser = $sharedPrompt->getUser();\n if ($sharedPrompt->isRemoved() === true) {\n $sharedUsersRemovedIds[] = $sharedUser->getId();\n }\n if ($sharedPrompt->isRemoved() !== true && $sharedUser instanceof User && $sharedUser->isStatusActive()) {\n $sharedUsersIds[] = $sharedUser->getId();\n $this->askAnythingRepository->createPrompt(\n $sharedUser,\n $prompt->getTarget(),\n $prompt->getTitle(),\n $prompt->getContent(),\n [],\n [],\n );\n $sharedPrompt->delete();\n }\n }\n\n return [$sharedUsersIds, $sharedUsersRemovedIds];\n }\n\n private function recreatePromptsForGroupRelations(AskAnythingPrompt $prompt, array $sharedUsersIds, array $sharedUsersRemovedIds): void\n {\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedGroup = $sharedPrompt->getGroup();\n if ($sharedGroup instanceof Group) {\n foreach ($sharedGroup->getMembers() as $member) {\n if (! in_array($member->getId(), $sharedUsersIds)\n && ! in_array($member->getId(), $sharedUsersRemovedIds)) {\n $sharedUsersIds[] = $member->getId();\n $this->askAnythingRepository->createPrompt(\n $member,\n $prompt->getTarget(),\n $prompt->getTitle(),\n $prompt->getContent(),\n [],\n [],\n );\n }\n }\n $sharedPrompt->delete();\n }\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
8246594430560437790
|
1126917008115010046
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\AskAnything;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
class AskAnythingPromptService
{
public function __construct(
private readonly AskAnythingRepository $askAnythingRepository,
private readonly UserRepository $userRepository,
private readonly GroupRepositoryInterface $groupRepository,
) {
}
/**
* @return array<AskAnythingPromptDto>
*/
public function get(User $user, AskAnythingPromptTarget $target): array
{
$prompts = $this->askAnythingRepository->findPromptsByUserAndTarget(
$user,
$target
);
$promptDtos = [];
foreach ($prompts as $prompt) {
$ownerUuid = null;
if ($prompt->getOwner() !== null) {
$ownerUuid = $prompt->getOwner()->getUuid();
}
$shareUsers = null;
$shareGroups = null;
// Provide users and groups only if owner of the prompt is current user
if ($prompt->getOwnerId() === $user->getId()) {
[$shareUsers, $shareGroups] = $this->getReceiverUuids($prompt);
}
$promptDtos[] = new AskAnythingPromptDto(
$prompt->getUuid(),
$prompt->getTitle(),
$prompt->getContent(),
$target,
$ownerUuid,
$shareUsers,
$shareGroups,
$prompt->getHasReports(),
);
}
return $promptDtos;
}
/**
* @param array<string> $shareUsersUuids
* @param array<string> $shareGroupsUuids
*/
public function create(
User $user,
string $title,
string $content,
AskAnythingPromptTarget $target,
array $shareUsersUuids,
array $shareGroupsUuids
): AskAnythingPromptDto {
$shareUsers = $shareGroups = [];
foreach ($shareUsersUuids as $userUuid) {
$shareUsers[] = $this->userRepository->findByUuid($userUuid);
}
foreach ($shareGroupsUuids as $groupUuid) {
$shareGroups[] = $this->groupRepository->findByUuid($groupUuid);
}
$prompt = $this->askAnythingRepository->createPrompt(
$user,
$target,
$title,
$content,
$shareUsers,
$shareGroups,
);
return new AskAnythingPromptDto(
$prompt->getUuid(),
$prompt->getTitle(),
$prompt->getContent(),
$target,
$user->getUuid(),
$shareUsersUuids,
$shareGroupsUuids,
$prompt->has_reports,
);
}
/**
* @param array<string> $shareUsersUuids
* @param array<string> $shareGroupsUuids
*
* @throws InvalidArgumentException
*/
public function edit(
AskAnythingPrompt $prompt,
User $user,
string $title,
string $content,
array $shareUsersUuids,
array $shareGroupsUuids
): AskAnythingPromptDto {
$shareUsers = $shareGroups = [];
foreach ($shareUsersUuids as $userUuid) {
$shareUsers[] = $this->userRepository->findByUuid($userUuid);
}
foreach ($shareGroupsUuids as $groupUuid) {
$shareGroups[] = $this->groupRepository->findByUuid($groupUuid);
}
if ($prompt->isDefaultPrompt()) {
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
$newPrompt = $this->askAnythingRepository->createPrompt(
$user,
$prompt->getTarget(),
$title,
$content,
$shareUsers,
$shareGroups,
);
} elseif ($prompt->getOwnerId() === $user->getId()) {
$newPrompt = $this->askAnythingRepository->editPrompt(
$prompt,
$title,
$content,
$shareUsers,
$shareGroups,
);
} else {
throw new InvalidArgumentException('Edit not allowed for prompt ' . $prompt->getUuid());
}
return new AskAnythingPromptDto(
$newPrompt->getUuid(),
$newPrompt->getTitle(),
$newPrompt->getContent(),
$newPrompt->getTarget(),
$user->getUuid(),
$shareUsersUuids,
$shareGroupsUuids,
$newPrompt->has_reports,
);
}
public function delete(
AskAnythingPrompt $prompt,
User $user
): AskAnythingPrompt {
if ($prompt->isDefaultPrompt()) {
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
} elseif ($prompt->getOwnerId() === $user->getId()) {
$userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);
$userPrompt?->delete();
// For each relation, re-create the prompt for the receiver as their own
$this->recreatePromptsForEachRelation($prompt);
// Finally, delete the prompt
$this->deletePromptIfNoRelations($prompt);
} else {
$userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);
$groupPrompt = $this->askAnythingRepository->findSharedPromptByUserGroup($prompt->getId(), $user);
// If the prompt is shared directly with the user, then "unshare" it
if ($userPrompt instanceof UserAskAnythingPrompt && $groupPrompt === null) {
$userPrompt->delete();
$this->deletePromptIfNoRelations($prompt);
} elseif ($groupPrompt instanceof UserAskAnythingPrompt) {
// If the prompt is shared with the user and the group, then hide it for this user
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
} else {
throw new InvalidArgumentException('Unknown delete allowance for prompt ' . $prompt->getUuid());
}
}
return $prompt;
}
public function reorder(
User $user,
array $promptUuids,
): void {
foreach ($promptUuids as $index => $promptUuid) {
$prompt = $this->askAnythingRepository->getPromptByUuid($promptUuid);
$this->askAnythingRepository->orderPromptForUser($prompt, $user, $index + 1);
}
}
/**
* @param AskAnythingPrompt $prompt
*
* @return array[array<string>, array<string>]
*/
private function getReceiverUuids(AskAnythingPrompt $prompt): array
{
$shareUsers = [];
$shareGroups = [];
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedUser = $sharedPrompt->getUser();
if ($sharedUser instanceof User && $sharedUser->isStatusActive()) {
$shareUsers[] = $sharedUser->getUuid();
}
$sharedGroup = $sharedPrompt->getGroup();
if ($sharedGroup instanceof Group) {
$shareGroups[] = $sharedGroup->getUuid();
}
}
return [$shareUsers, $shareGroups];
}
private function deletePromptIfNoRelations(AskAnythingPrompt $prompt): void
{
if ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId())->isEmpty()) {
// Disable and orphan any AutomatedReports that use this prompt
$prompt->automatedReports()->withTrashed()->update([
'ask_anything_prompt_id' => null,
'status' => false,
]);
// Delete only if there are no other relations to it.
$this->askAnythingRepository->deletePrompt($prompt);
}
}
private function recreatePromptsForEachRelation(AskAnythingPrompt $prompt): void
{
[$sharedUsersIds, $sharedUsersRemovedIds] = $this->recreatePromptsForUserRelations($prompt);
$this->recreatePromptsForGroupRelations($prompt, $sharedUsersIds, $sharedUsersRemovedIds);
}
private function recreatePromptsForUserRelations(AskAnythingPrompt $prompt): array
{
$sharedUsersIds = [];
$sharedUsersRemovedIds = [];
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedUser = $sharedPrompt->getUser();
if ($sharedPrompt->isRemoved() === true) {
$sharedUsersRemovedIds[] = $sharedUser->getId();
}
if ($sharedPrompt->isRemoved() !== true && $sharedUser instanceof User && $sharedUser->isStatusActive()) {
$sharedUsersIds[] = $sharedUser->getId();
$this->askAnythingRepository->createPrompt(
$sharedUser,
$prompt->getTarget(),
$prompt->getTitle(),
$prompt->getContent(),
[],
[],
);
$sharedPrompt->delete();
}
}
return [$sharedUsersIds, $sharedUsersRemovedIds];
}
private function recreatePromptsForGroupRelations(AskAnythingPrompt $prompt, array $sharedUsersIds, array $sharedUsersRemovedIds): void
{
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedGroup = $sharedPrompt->getGroup();
if ($sharedGroup instanceof Group) {
foreach ($sharedGroup->getMembers() as $member) {
if (! in_array($member->getId(), $sharedUsersIds)
&& ! in_array($member->getId(), $sharedUsersRemovedIds)) {
$sharedUsersIds[] = $member->getId();
$this->askAnythingRepository->createPrompt(
$member,
$prompt->getTarget(),
$prompt->getTitle(),
$prompt->getContent(),
[],
[],
);
}
}
$sharedPrompt->delete();
}
}
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56819
|
NULL
|
NULL
|
NULL
|
|
56822
|
1975
|
9
|
2026-05-19T08:27:02.698218+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179222698_m2.jpg...
|
PhpStorm
|
faVsco.js – SearchTransformer.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
<?php
namespace Jiminny\Http\Transformers;
use Illuminate\Support\LazyCollection;
use Jiminny\Component;
use Jiminny\Component\ActivitySearch\Service\ActivitySearch;
use Jiminny\Exceptions\OutOfBoundsException;
use Jiminny\Component\Nudge\Http\Transformer\NudgeTransformer;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\User;
use League\Fractal;
use League\Fractal\TransformerAbstract;
use Psr\Log\LoggerInterface;
class SearchTransformer extends TransformerAbstract
{
protected array $availableIncludes = [
'nudges',
];
protected array $defaultIncludes = [
'nudges',
];
private User $consumer;
public function __construct(
private readonly ActivitySearch $activitySearch,
private readonly NudgeTransformer $nudgeTransformer,
private readonly LoggerInterface $logger,
) {
}
public function withConsumer(User $user): self
{
$this->consumer = $user;
return $this;
}
public function transform(Search $search): array
{
return [
'id' => $search->id_string,
'name' => $search->getName(),
'filters' => $this->getFilters($search),
'has_reports' => $search->automatedReports()->exists(),
];
}
public function includeNudges(Search $search): Fractal\Resource\Collection
{
return $this->collection($search->getNudges(), $this->nudgeTransformer);
}
public function getFilters(Search $search): array
{
$filterSet = $this->activitySearch->getOnDemandPageFilters()
->withConsumer($this->consumer);
$propertyTypes = $filterSet->getPropertyTypes();
$allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();
/** @var LazyCollection<int, SearchFilter> $searchFilters */
$searchFilters = $search->getFilters();
$preProcessed = [];
foreach ($searchFilters as $searchFilter) {
$filterValue = $searchFilter->getFilterValue();
$filterProperty = $searchFilter->getFilterProperty();
if (! $propertyTypes->has($filterProperty)) {
$this->logger->debug(__METHOD__ . ': unsupported property', [
'property' => $filterProperty,
'available' => $propertyTypes->keys()->all(),
]);
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
continue;
}
if (! $allowedFilters->has($filterProperty)) {
continue;
}
/** @var string $propertyType */
$propertyType = $propertyTypes->get($filterProperty);
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {
if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {
$preProcessed[$searchFilter->getFilterProperty()] = [];
}
$preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;
continue;
}
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {
$filterValue = (int) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {
$filterValue = (float) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {
$filterValue = (int) $filterValue;
} elseif ($propertyType !== Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {
throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));
}
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
}
return $preProcessed;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.098071806,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Http\\Transformers;\n\nuse Illuminate\\Support\\LazyCollection;\nuse Jiminny\\Component;\nuse Jiminny\\Component\\ActivitySearch\\Service\\ActivitySearch;\nuse Jiminny\\Exceptions\\OutOfBoundsException;\nuse Jiminny\\Component\\Nudge\\Http\\Transformer\\NudgeTransformer;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\User;\nuse League\\Fractal;\nuse League\\Fractal\\TransformerAbstract;\nuse Psr\\Log\\LoggerInterface;\n\nclass SearchTransformer extends TransformerAbstract\n{\n protected array $availableIncludes = [\n 'nudges',\n ];\n\n protected array $defaultIncludes = [\n 'nudges',\n ];\n private User $consumer;\n\n public function __construct(\n private readonly ActivitySearch $activitySearch,\n private readonly NudgeTransformer $nudgeTransformer,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n public function withConsumer(User $user): self\n {\n $this->consumer = $user;\n\n return $this;\n }\n\n public function transform(Search $search): array\n {\n return [\n 'id' => $search->id_string,\n 'name' => $search->getName(),\n 'filters' => $this->getFilters($search),\n 'has_reports' => $search->automatedReports()->exists(),\n ];\n }\n\n public function includeNudges(Search $search): Fractal\\Resource\\Collection\n {\n return $this->collection($search->getNudges(), $this->nudgeTransformer);\n }\n\n public function getFilters(Search $search): array\n {\n $filterSet = $this->activitySearch->getOnDemandPageFilters()\n ->withConsumer($this->consumer);\n\n $propertyTypes = $filterSet->getPropertyTypes();\n $allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();\n\n /** @var LazyCollection<int, SearchFilter> $searchFilters */\n $searchFilters = $search->getFilters();\n\n $preProcessed = [];\n\n foreach ($searchFilters as $searchFilter) {\n $filterValue = $searchFilter->getFilterValue();\n $filterProperty = $searchFilter->getFilterProperty();\n\n if (! $propertyTypes->has($filterProperty)) {\n $this->logger->debug(__METHOD__ . ': unsupported property', [\n 'property' => $filterProperty,\n 'available' => $propertyTypes->keys()->all(),\n ]);\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n\n continue;\n }\n\n if (! $allowedFilters->has($filterProperty)) {\n continue;\n }\n\n /** @var string $propertyType */\n $propertyType = $propertyTypes->get($filterProperty);\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {\n if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {\n $preProcessed[$searchFilter->getFilterProperty()] = [];\n }\n\n $preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;\n\n continue;\n }\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {\n $filterValue = (float) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType !== Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {\n throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));\n }\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n }\n\n return $preProcessed;\n }\n}","depth":4,"bounds":{"left":0.15990691,"top":0.083798885,"width":0.26728722,"height":0.8954509},"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Http\\Transformers;\n\nuse Illuminate\\Support\\LazyCollection;\nuse Jiminny\\Component;\nuse Jiminny\\Component\\ActivitySearch\\Service\\ActivitySearch;\nuse Jiminny\\Exceptions\\OutOfBoundsException;\nuse Jiminny\\Component\\Nudge\\Http\\Transformer\\NudgeTransformer;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\User;\nuse League\\Fractal;\nuse League\\Fractal\\TransformerAbstract;\nuse Psr\\Log\\LoggerInterface;\n\nclass SearchTransformer extends TransformerAbstract\n{\n protected array $availableIncludes = [\n 'nudges',\n ];\n\n protected array $defaultIncludes = [\n 'nudges',\n ];\n private User $consumer;\n\n public function __construct(\n private readonly ActivitySearch $activitySearch,\n private readonly NudgeTransformer $nudgeTransformer,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n public function withConsumer(User $user): self\n {\n $this->consumer = $user;\n\n return $this;\n }\n\n public function transform(Search $search): array\n {\n return [\n 'id' => $search->id_string,\n 'name' => $search->getName(),\n 'filters' => $this->getFilters($search),\n 'has_reports' => $search->automatedReports()->exists(),\n ];\n }\n\n public function includeNudges(Search $search): Fractal\\Resource\\Collection\n {\n return $this->collection($search->getNudges(), $this->nudgeTransformer);\n }\n\n public function getFilters(Search $search): array\n {\n $filterSet = $this->activitySearch->getOnDemandPageFilters()\n ->withConsumer($this->consumer);\n\n $propertyTypes = $filterSet->getPropertyTypes();\n $allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();\n\n /** @var LazyCollection<int, SearchFilter> $searchFilters */\n $searchFilters = $search->getFilters();\n\n $preProcessed = [];\n\n foreach ($searchFilters as $searchFilter) {\n $filterValue = $searchFilter->getFilterValue();\n $filterProperty = $searchFilter->getFilterProperty();\n\n if (! $propertyTypes->has($filterProperty)) {\n $this->logger->debug(__METHOD__ . ': unsupported property', [\n 'property' => $filterProperty,\n 'available' => $propertyTypes->keys()->all(),\n ]);\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n\n continue;\n }\n\n if (! $allowedFilters->has($filterProperty)) {\n continue;\n }\n\n /** @var string $propertyType */\n $propertyType = $propertyTypes->get($filterProperty);\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {\n if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {\n $preProcessed[$searchFilter->getFilterProperty()] = [];\n }\n\n $preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;\n\n continue;\n }\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {\n $filterValue = (float) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType !== Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {\n throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));\n }\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n }\n\n return $preProcessed;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.7124335,"top":0.10055866,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.72140956,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7287234,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
1884092436306358511
|
-8920241438572008599
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
<?php
namespace Jiminny\Http\Transformers;
use Illuminate\Support\LazyCollection;
use Jiminny\Component;
use Jiminny\Component\ActivitySearch\Service\ActivitySearch;
use Jiminny\Exceptions\OutOfBoundsException;
use Jiminny\Component\Nudge\Http\Transformer\NudgeTransformer;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\User;
use League\Fractal;
use League\Fractal\TransformerAbstract;
use Psr\Log\LoggerInterface;
class SearchTransformer extends TransformerAbstract
{
protected array $availableIncludes = [
'nudges',
];
protected array $defaultIncludes = [
'nudges',
];
private User $consumer;
public function __construct(
private readonly ActivitySearch $activitySearch,
private readonly NudgeTransformer $nudgeTransformer,
private readonly LoggerInterface $logger,
) {
}
public function withConsumer(User $user): self
{
$this->consumer = $user;
return $this;
}
public function transform(Search $search): array
{
return [
'id' => $search->id_string,
'name' => $search->getName(),
'filters' => $this->getFilters($search),
'has_reports' => $search->automatedReports()->exists(),
];
}
public function includeNudges(Search $search): Fractal\Resource\Collection
{
return $this->collection($search->getNudges(), $this->nudgeTransformer);
}
public function getFilters(Search $search): array
{
$filterSet = $this->activitySearch->getOnDemandPageFilters()
->withConsumer($this->consumer);
$propertyTypes = $filterSet->getPropertyTypes();
$allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();
/** @var LazyCollection<int, SearchFilter> $searchFilters */
$searchFilters = $search->getFilters();
$preProcessed = [];
foreach ($searchFilters as $searchFilter) {
$filterValue = $searchFilter->getFilterValue();
$filterProperty = $searchFilter->getFilterProperty();
if (! $propertyTypes->has($filterProperty)) {
$this->logger->debug(__METHOD__ . ': unsupported property', [
'property' => $filterProperty,
'available' => $propertyTypes->keys()->all(),
]);
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
continue;
}
if (! $allowedFilters->has($filterProperty)) {
continue;
}
/** @var string $propertyType */
$propertyType = $propertyTypes->get($filterProperty);
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {
if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {
$preProcessed[$searchFilter->getFilterProperty()] = [];
}
$preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;
continue;
}
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {
$filterValue = (int) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {
$filterValue = (float) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {
$filterValue = (int) $filterValue;
} elseif ($propertyType !== Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {
throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));
}
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
}
return $preProcessed;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error...
|
56820
|
NULL
|
NULL
|
NULL
|
|
56823
|
1975
|
10
|
2026-05-19T08:27:12.489295+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179232489_m2.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptDto.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
PhostormViewINavicarecodeLaravelKeractorWindowFV f PhostormViewINavicarecodeLaravelKeractorWindowFV faVsco.js?9 JY-20676-delete-report-related-objectsProiectC ActivityController.ong© AskAnythingController.php(C) CoachinaSectionFeedbacksTransformen© AskAnythingPromptService.php© AskAnythingPrompt.phpphp api_v2.phpC) CoachingsectionsIranstormer.onp© CoachingSectionTransformer.php(c) CommentiranstormerAbstract.ono© AutomatedReport.php©) AskAnythingPromptServiceTest.phpoconnection transtormer.onpo contdellranstormer.ong© CrmTemplateFieldTransformer.phpc crmiemplatelranstormer.onp© CrmTransformer.phpDatalranstormer.onpc DealstageIranstormer.pnpc) reaturelranstormer.pnp© FieldTransformer.phpc) rielcvalue lranstormer.ono© ForecastTransformer.phpc) GroupDealRiskTvoeTranstormer.oho© GroupTransformer.php©Intearationtiranstormer.oho© Invitation Transformer.ohpc) ,oo tetranstormer.ono© LanquageDialectTransformer.ohp© LayoutEntityTransformer.php©LayoutTransformer.phpC) Leadtransformer.oho@ MessageTransformer.oho© MomentTransformer.php© NoteTransformer.php© NotificationTransformer.php© OnDemandActivitiesTransformer.php© OpportunityCommentTransformer.php© OpportunityTransformer.php(c) Particinantranstormer.ong© PartnerTransformer.php© PermissionTransformer.php© PlaybackPageTransformer.php© PlaybookTransformer.php© PlaybookTreeTransformer.phpPlaylistActivityTransformer.phpPlavlistSharesTransformer.phpPlavlistTransformer.phpc)Prosoectsfranstormer.onoc) @uestioniranstormer.onoC) RecordTivoeTransformer.ohoC) RoleTransformer.ohoC) SconeGrouotiransformer.ohoC) ScorecardRuleTiransformer.ohoC) ScorecardRuleTriagerTransformer.oho(c) Scorecardtiransformer nhnl(c) SoarchTransformer nhn(C) Saccion Transformer nhn) search.phpnamespace Jiminny component ASkAnychino ucosuse Jiminny Models AskAnythinqAskAnyth1nqPromptlarqet:class ASKAnythingPromptbtopublic function -_constructlpublac strind s1dpublic string Stitle,public string Scontent,public AskAnythingPromptTarget $target,public ?string Sownerld = null,public ?array $shareUsers = null,public ?array $shareGroups = null,public ?bool $hasReports = null,public function toArray: arraySdata =rl'id' => Sthis->id!'title' => sthis->t1tle.'content = sth1s->content.'target' => Sthis->target->nameif (Sthis->ownerId |== null) {Sdatal 'owner id'1 = Sthis->ownerId:if (Sthis->sharellsens |== null) {Sdatali'share users' = Sthis->shareUsers:if (Sthis->shaneGnouns f== null) fSdatal"share arouns!l = Sthis->chareGrouns.if ($this->hasReports |== null) {Cdatafthae nonontel' = Sthic-shacPononte.(C) StadeTransformer nhnreturn Sdatf.1 of2 editsyAccept File &+X Reject File t*a+ 3 01 3 filles →The Huncnell nluain hac heon denrecated. If voulre not writing in Hungarian vou can cafolv uninctall Hunsnell without affecting the dictiaaec (today 10-00)AcceptReiect= custom.log= laravel.log4 SF jiminny@localhost]4 HS_local [jiminny@localhost]& console [PROD]# console [euyA console [STAGING]© CoachingFeedbackCoachUserln.php X<?phpdeclare(scrict_cypes=l)nnamespace Jiminny Component Activ1tySearch Filterder1n1t1on:› use ...final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface29 >34 đ >45 đ >118135136 ct ›146 đt ›150151 Gt$usadeorivate const int No GROUP 10 = 9993 usagesorivate UserRenository SuserRenository:public function __construct(UserRepository $userRepository)f...hpublic function shouldApplyQueries: boolf...}public function getQueries: FilterDefinitionQueryCollection{...hpublic function toArray@: array{...hprivate function getOptions(): array{...}public function getValue®: array{...}private function getDefaultValue: array{...}public function aetValidationRules(2strina Sorefix = null): arrav{...}public function aetSortOrder@: intf...}public function shouldBeIncluded(Team $team): bool{...}"suppont Dally • In 3n 33m100% Lz• Tue 19 May 11:27:12AskJiminnyReportActivityServiceTest vCascadeASK Jiminny Reportseview it prim.reports propertyWhat is there is no ask liminny report realted at all. Most of them will be withoutThouaht for 1skead searchlranstormer.onp and & oter tllesThouaht for 4sSearchTransformer.nho+0..Now rework the DTo: make hasRenorts nullable so has revorts is oniv included for the list endooint (not create/uodate),• AskAnythingPromptDto.php409 tokensw* Reiect allAccent alliAsk anvthina (84L)<> Code Claude Qnus 1.7 MediumWN Windsurf Teams10-1UTE.8io 4 spaces...
|
NULL
|
377118701730599240
|
NULL
|
visual_change
|
ocr
|
NULL
|
PhostormViewINavicarecodeLaravelKeractorWindowFV f PhostormViewINavicarecodeLaravelKeractorWindowFV faVsco.js?9 JY-20676-delete-report-related-objectsProiectC ActivityController.ong© AskAnythingController.php(C) CoachinaSectionFeedbacksTransformen© AskAnythingPromptService.php© AskAnythingPrompt.phpphp api_v2.phpC) CoachingsectionsIranstormer.onp© CoachingSectionTransformer.php(c) CommentiranstormerAbstract.ono© AutomatedReport.php©) AskAnythingPromptServiceTest.phpoconnection transtormer.onpo contdellranstormer.ong© CrmTemplateFieldTransformer.phpc crmiemplatelranstormer.onp© CrmTransformer.phpDatalranstormer.onpc DealstageIranstormer.pnpc) reaturelranstormer.pnp© FieldTransformer.phpc) rielcvalue lranstormer.ono© ForecastTransformer.phpc) GroupDealRiskTvoeTranstormer.oho© GroupTransformer.php©Intearationtiranstormer.oho© Invitation Transformer.ohpc) ,oo tetranstormer.ono© LanquageDialectTransformer.ohp© LayoutEntityTransformer.php©LayoutTransformer.phpC) Leadtransformer.oho@ MessageTransformer.oho© MomentTransformer.php© NoteTransformer.php© NotificationTransformer.php© OnDemandActivitiesTransformer.php© OpportunityCommentTransformer.php© OpportunityTransformer.php(c) Particinantranstormer.ong© PartnerTransformer.php© PermissionTransformer.php© PlaybackPageTransformer.php© PlaybookTransformer.php© PlaybookTreeTransformer.phpPlaylistActivityTransformer.phpPlavlistSharesTransformer.phpPlavlistTransformer.phpc)Prosoectsfranstormer.onoc) @uestioniranstormer.onoC) RecordTivoeTransformer.ohoC) RoleTransformer.ohoC) SconeGrouotiransformer.ohoC) ScorecardRuleTiransformer.ohoC) ScorecardRuleTriagerTransformer.oho(c) Scorecardtiransformer nhnl(c) SoarchTransformer nhn(C) Saccion Transformer nhn) search.phpnamespace Jiminny component ASkAnychino ucosuse Jiminny Models AskAnythinqAskAnyth1nqPromptlarqet:class ASKAnythingPromptbtopublic function -_constructlpublac strind s1dpublic string Stitle,public string Scontent,public AskAnythingPromptTarget $target,public ?string Sownerld = null,public ?array $shareUsers = null,public ?array $shareGroups = null,public ?bool $hasReports = null,public function toArray: arraySdata =rl'id' => Sthis->id!'title' => sthis->t1tle.'content = sth1s->content.'target' => Sthis->target->nameif (Sthis->ownerId |== null) {Sdatal 'owner id'1 = Sthis->ownerId:if (Sthis->sharellsens |== null) {Sdatali'share users' = Sthis->shareUsers:if (Sthis->shaneGnouns f== null) fSdatal"share arouns!l = Sthis->chareGrouns.if ($this->hasReports |== null) {Cdatafthae nonontel' = Sthic-shacPononte.(C) StadeTransformer nhnreturn Sdatf.1 of2 editsyAccept File &+X Reject File t*a+ 3 01 3 filles →The Huncnell nluain hac heon denrecated. If voulre not writing in Hungarian vou can cafolv uninctall Hunsnell without affecting the dictiaaec (today 10-00)AcceptReiect= custom.log= laravel.log4 SF jiminny@localhost]4 HS_local [jiminny@localhost]& console [PROD]# console [euyA console [STAGING]© CoachingFeedbackCoachUserln.php X<?phpdeclare(scrict_cypes=l)nnamespace Jiminny Component Activ1tySearch Filterder1n1t1on:› use ...final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface29 >34 đ >45 đ >118135136 ct ›146 đt ›150151 Gt$usadeorivate const int No GROUP 10 = 9993 usagesorivate UserRenository SuserRenository:public function __construct(UserRepository $userRepository)f...hpublic function shouldApplyQueries: boolf...}public function getQueries: FilterDefinitionQueryCollection{...hpublic function toArray@: array{...hprivate function getOptions(): array{...}public function getValue®: array{...}private function getDefaultValue: array{...}public function aetValidationRules(2strina Sorefix = null): arrav{...}public function aetSortOrder@: intf...}public function shouldBeIncluded(Team $team): bool{...}"suppont Dally • In 3n 33m100% Lz• Tue 19 May 11:27:12AskJiminnyReportActivityServiceTest vCascadeASK Jiminny Reportseview it prim.reports propertyWhat is there is no ask liminny report realted at all. Most of them will be withoutThouaht for 1skead searchlranstormer.onp and & oter tllesThouaht for 4sSearchTransformer.nho+0..Now rework the DTo: make hasRenorts nullable so has revorts is oniv included for the list endooint (not create/uodate),• AskAnythingPromptDto.php409 tokensw* Reiect allAccent alliAsk anvthina (84L)<> Code Claude Qnus 1.7 MediumWN Windsurf Teams10-1UTE.8io 4 spaces...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
56824
|
1974
|
8
|
2026-05-19T08:27:14.196090+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179234196_m1.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptDto.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\AskAnything\Dtos;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
class AskAnythingPromptDto
{
public function __construct(
public string $id,
public string $title,
public string $content,
public AskAnythingPromptTarget $target,
public ?string $ownerId = null,
public ?array $shareUsers = null,
public ?array $shareGroups = null,
public ?bool $hasReports = null,
) {
}
public function toArray(): array
{
$data = [
'id' => $this->id,
'title' => $this->title,
'content' => $this->content,
'target' => $this->target->name,
];
if ($this->ownerId !== null) {
$data['owner_id'] = $this->ownerId;
}
if ($this->shareUsers !== null) {
$data['share_users'] = $this->shareUsers;
}
if ($this->shareGroups !== null) {
$data['share_groups'] = $this->shareGroups;
}
if ($this->hasReports !== null) {
$data['has_reports'] = $this->hasReports;
}
return $data;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\AskAnything\\Dtos;\n\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\n\nclass AskAnythingPromptDto\n{\n public function __construct(\n public string $id,\n public string $title,\n public string $content,\n public AskAnythingPromptTarget $target,\n public ?string $ownerId = null,\n public ?array $shareUsers = null,\n public ?array $shareGroups = null,\n public ?bool $hasReports = null,\n ) {\n\n }\n\n public function toArray(): array\n {\n $data = [\n 'id' => $this->id,\n 'title' => $this->title,\n 'content' => $this->content,\n 'target' => $this->target->name,\n ];\n\n if ($this->ownerId !== null) {\n $data['owner_id'] = $this->ownerId;\n }\n\n if ($this->shareUsers !== null) {\n $data['share_users'] = $this->shareUsers;\n }\n\n if ($this->shareGroups !== null) {\n $data['share_groups'] = $this->shareGroups;\n }\n\n if ($this->hasReports !== null) {\n $data['has_reports'] = $this->hasReports;\n }\n\n return $data;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\AskAnything\\Dtos;\n\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\n\nclass AskAnythingPromptDto\n{\n public function __construct(\n public string $id,\n public string $title,\n public string $content,\n public AskAnythingPromptTarget $target,\n public ?string $ownerId = null,\n public ?array $shareUsers = null,\n public ?array $shareGroups = null,\n public ?bool $hasReports = null,\n ) {\n\n }\n\n public function toArray(): array\n {\n $data = [\n 'id' => $this->id,\n 'title' => $this->title,\n 'content' => $this->content,\n 'target' => $this->target->name,\n ];\n\n if ($this->ownerId !== null) {\n $data['owner_id'] = $this->ownerId;\n }\n\n if ($this->shareUsers !== null) {\n $data['share_users'] = $this->shareUsers;\n }\n\n if ($this->shareGroups !== null) {\n $data['share_groups'] = $this->shareGroups;\n }\n\n if ($this->hasReports !== null) {\n $data['has_reports'] = $this->hasReports;\n }\n\n return $data;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-5175572695641837705
|
-2561334970159157332
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\AskAnything\Dtos;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
class AskAnythingPromptDto
{
public function __construct(
public string $id,
public string $title,
public string $content,
public AskAnythingPromptTarget $target,
public ?string $ownerId = null,
public ?array $shareUsers = null,
public ?array $shareGroups = null,
public ?bool $hasReports = null,
) {
}
public function toArray(): array
{
$data = [
'id' => $this->id,
'title' => $this->title,
'content' => $this->content,
'target' => $this->target->name,
];
if ($this->ownerId !== null) {
$data['owner_id'] = $this->ownerId;
}
if ($this->shareUsers !== null) {
$data['share_users'] = $this->shareUsers;
}
if ($this->shareGroups !== null) {
$data['share_groups'] = $this->shareGroups;
}
if ($this->hasReports !== null) {
$data['has_reports'] = $this->hasReports;
}
return $data;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56819
|
NULL
|
NULL
|
NULL
|
|
56825
|
1975
|
11
|
2026-05-19T08:27:24.557273+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179244557_m2.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\AskAnything;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
class AskAnythingPromptService
{
public function __construct(
private readonly AskAnythingRepository $askAnythingRepository,
private readonly UserRepository $userRepository,
private readonly GroupRepositoryInterface $groupRepository,
) {
}
/**
* @return array<AskAnythingPromptDto>
*/
public function get(User $user, AskAnythingPromptTarget $target): array
{
$prompts = $this->askAnythingRepository->findPromptsByUserAndTarget(
$user,
$target
);
$promptDtos = [];
foreach ($prompts as $prompt) {
$ownerUuid = null;
if ($prompt->getOwner() !== null) {
$ownerUuid = $prompt->getOwner()->getUuid();
}
$shareUsers = null;
$shareGroups = null;
// Provide users and groups only if owner of the prompt is current user
if ($prompt->getOwnerId() === $user->getId()) {
[$shareUsers, $shareGroups] = $this->getReceiverUuids($prompt);
}
$promptDtos[] = new AskAnythingPromptDto(
$prompt->getUuid(),
$prompt->getTitle(),
$prompt->getContent(),
$target,
$ownerUuid,
$shareUsers,
$shareGroups,
$prompt->getHasReports(),
);
}
return $promptDtos;
}
/**
* @param array<string> $shareUsersUuids
* @param array<string> $shareGroupsUuids
*/
public function create(
User $user,
string $title,
string $content,
AskAnythingPromptTarget $target,
array $shareUsersUuids,
array $shareGroupsUuids
): AskAnythingPromptDto {
$shareUsers = $shareGroups = [];
foreach ($shareUsersUuids as $userUuid) {
$shareUsers[] = $this->userRepository->findByUuid($userUuid);
}
foreach ($shareGroupsUuids as $groupUuid) {
$shareGroups[] = $this->groupRepository->findByUuid($groupUuid);
}
$prompt = $this->askAnythingRepository->createPrompt(
$user,
$target,
$title,
$content,
$shareUsers,
$shareGroups,
);
return new AskAnythingPromptDto(
$prompt->getUuid(),
$prompt->getTitle(),
$prompt->getContent(),
$target,
$user->getUuid(),
$shareUsersUuids,
$shareGroupsUuids,
);
}
/**
* @param array<string> $shareUsersUuids
* @param array<string> $shareGroupsUuids
*
* @throws InvalidArgumentException
*/
public function edit(
AskAnythingPrompt $prompt,
User $user,
string $title,
string $content,
array $shareUsersUuids,
array $shareGroupsUuids
): AskAnythingPromptDto {
$shareUsers = $shareGroups = [];
foreach ($shareUsersUuids as $userUuid) {
$shareUsers[] = $this->userRepository->findByUuid($userUuid);
}
foreach ($shareGroupsUuids as $groupUuid) {
$shareGroups[] = $this->groupRepository->findByUuid($groupUuid);
}
if ($prompt->isDefaultPrompt()) {
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
$newPrompt = $this->askAnythingRepository->createPrompt(
$user,
$prompt->getTarget(),
$title,
$content,
$shareUsers,
$shareGroups,
);
} elseif ($prompt->getOwnerId() === $user->getId()) {
$newPrompt = $this->askAnythingRepository->editPrompt(
$prompt,
$title,
$content,
$shareUsers,
$shareGroups,
);
} else {
throw new InvalidArgumentException('Edit not allowed for prompt ' . $prompt->getUuid());
}
return new AskAnythingPromptDto(
$newPrompt->getUuid(),
$newPrompt->getTitle(),
$newPrompt->getContent(),
$newPrompt->getTarget(),
$user->getUuid(),
$shareUsersUuids,
$shareGroupsUuids,
);
}
public function delete(
AskAnythingPrompt $prompt,
User $user
): AskAnythingPrompt {
if ($prompt->isDefaultPrompt()) {
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
} elseif ($prompt->getOwnerId() === $user->getId()) {
$userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);
$userPrompt?->delete();
// For each relation, re-create the prompt for the receiver as their own
$this->recreatePromptsForEachRelation($prompt);
// Finally, delete the prompt
$this->deletePromptIfNoRelations($prompt);
} else {
$userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);
$groupPrompt = $this->askAnythingRepository->findSharedPromptByUserGroup($prompt->getId(), $user);
// If the prompt is shared directly with the user, then "unshare" it
if ($userPrompt instanceof UserAskAnythingPrompt && $groupPrompt === null) {
$userPrompt->delete();
$this->deletePromptIfNoRelations($prompt);
} elseif ($groupPrompt instanceof UserAskAnythingPrompt) {
// If the prompt is shared with the user and the group, then hide it for this user
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
} else {
throw new InvalidArgumentException('Unknown delete allowance for prompt ' . $prompt->getUuid());
}
}
return $prompt;
}
public function reorder(
User $user,
array $promptUuids,
): void {
foreach ($promptUuids as $index => $promptUuid) {
$prompt = $this->askAnythingRepository->getPromptByUuid($promptUuid);
$this->askAnythingRepository->orderPromptForUser($prompt, $user, $index + 1);
}
}
/**
* @param AskAnythingPrompt $prompt
*
* @return array[array<string>, array<string>]
*/
private function getReceiverUuids(AskAnythingPrompt $prompt): array
{
$shareUsers = [];
$shareGroups = [];
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedUser = $sharedPrompt->getUser();
if ($sharedUser instanceof User && $sharedUser->isStatusActive()) {
$shareUsers[] = $sharedUser->getUuid();
}
$sharedGroup = $sharedPrompt->getGroup();
if ($sharedGroup instanceof Group) {
$shareGroups[] = $sharedGroup->getUuid();
}
}
return [$shareUsers, $shareGroups];
}
private function deletePromptIfNoRelations(AskAnythingPrompt $prompt): void
{
if ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId())->isEmpty()) {
// Disable and orphan any AutomatedReports that use this prompt
$prompt->automatedReports()->withTrashed()->update([
'ask_anything_prompt_id' => null,
'status' => false,
]);
// Delete only if there are no other relations to it.
$this->askAnythingRepository->deletePrompt($prompt);
}
}
private function recreatePromptsForEachRelation(AskAnythingPrompt $prompt): void
{
[$sharedUsersIds, $sharedUsersRemovedIds] = $this->recreatePromptsForUserRelations($prompt);
$this->recreatePromptsForGroupRelations($prompt, $sharedUsersIds, $sharedUsersRemovedIds);
}
private function recreatePromptsForUserRelations(AskAnythingPrompt $prompt): array
{
$sharedUsersIds = [];
$sharedUsersRemovedIds = [];
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedUser = $sharedPrompt->getUser();
if ($sharedPrompt->isRemoved() === true) {
$sharedUsersRemovedIds[] = $sharedUser->getId();
}
if ($sharedPrompt->isRemoved() !== true && $sharedUser instanceof User && $sharedUser->isStatusActive()) {
$sharedUsersIds[] = $sharedUser->getId();
$this->askAnythingRepository->createPrompt(
$sharedUser,
$prompt->getTarget(),
$prompt->getTitle(),
$prompt->getContent(),
[],
[],
);
$sharedPrompt->delete();
}
}
return [$sharedUsersIds, $sharedUsersRemovedIds];
}
private function recreatePromptsForGroupRelations(AskAnythingPrompt $prompt, array $sharedUsersIds, array $sharedUsersRemovedIds): void
{
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedGroup = $sharedPrompt->getGroup();
if ($sharedGroup instanceof Group) {
foreach ($sharedGroup->getMembers() as $member) {
if (! in_array($member->getId(), $sharedUsersIds)
&& ! in_array($member->getId(), $sharedUsersRemovedIds)) {
$sharedUsersIds[] = $member->getId();
$this->askAnythingRepository->createPrompt(
$member,
$prompt->getTarget(),
$prompt->getTitle(),
$prompt->getContent(),
[],
[],
);
}
}
$sharedPrompt->delete();
}
}
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.098071806,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"4","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.007978723,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.007978723,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\AskAnything;\n\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\n\nclass AskAnythingPromptService\n{\n public function __construct(\n private readonly AskAnythingRepository $askAnythingRepository,\n private readonly UserRepository $userRepository,\n private readonly GroupRepositoryInterface $groupRepository,\n ) {\n }\n\n /**\n * @return array<AskAnythingPromptDto>\n */\n public function get(User $user, AskAnythingPromptTarget $target): array\n {\n $prompts = $this->askAnythingRepository->findPromptsByUserAndTarget(\n $user,\n $target\n );\n\n $promptDtos = [];\n foreach ($prompts as $prompt) {\n $ownerUuid = null;\n if ($prompt->getOwner() !== null) {\n $ownerUuid = $prompt->getOwner()->getUuid();\n }\n $shareUsers = null;\n $shareGroups = null;\n\n // Provide users and groups only if owner of the prompt is current user\n if ($prompt->getOwnerId() === $user->getId()) {\n [$shareUsers, $shareGroups] = $this->getReceiverUuids($prompt);\n }\n\n $promptDtos[] = new AskAnythingPromptDto(\n $prompt->getUuid(),\n $prompt->getTitle(),\n $prompt->getContent(),\n $target,\n $ownerUuid,\n $shareUsers,\n $shareGroups,\n $prompt->getHasReports(),\n );\n }\n\n return $promptDtos;\n }\n\n /**\n * @param array<string> $shareUsersUuids\n * @param array<string> $shareGroupsUuids\n */\n public function create(\n User $user,\n string $title,\n string $content,\n AskAnythingPromptTarget $target,\n array $shareUsersUuids,\n array $shareGroupsUuids\n ): AskAnythingPromptDto {\n\n $shareUsers = $shareGroups = [];\n foreach ($shareUsersUuids as $userUuid) {\n $shareUsers[] = $this->userRepository->findByUuid($userUuid);\n }\n foreach ($shareGroupsUuids as $groupUuid) {\n $shareGroups[] = $this->groupRepository->findByUuid($groupUuid);\n }\n\n $prompt = $this->askAnythingRepository->createPrompt(\n $user,\n $target,\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n\n return new AskAnythingPromptDto(\n $prompt->getUuid(),\n $prompt->getTitle(),\n $prompt->getContent(),\n $target,\n $user->getUuid(),\n $shareUsersUuids,\n $shareGroupsUuids,\n );\n }\n\n /**\n * @param array<string> $shareUsersUuids\n * @param array<string> $shareGroupsUuids\n *\n * @throws InvalidArgumentException\n */\n public function edit(\n AskAnythingPrompt $prompt,\n User $user,\n string $title,\n string $content,\n array $shareUsersUuids,\n array $shareGroupsUuids\n ): AskAnythingPromptDto {\n $shareUsers = $shareGroups = [];\n foreach ($shareUsersUuids as $userUuid) {\n $shareUsers[] = $this->userRepository->findByUuid($userUuid);\n }\n foreach ($shareGroupsUuids as $groupUuid) {\n $shareGroups[] = $this->groupRepository->findByUuid($groupUuid);\n }\n\n if ($prompt->isDefaultPrompt()) {\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n\n $newPrompt = $this->askAnythingRepository->createPrompt(\n $user,\n $prompt->getTarget(),\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n } elseif ($prompt->getOwnerId() === $user->getId()) {\n $newPrompt = $this->askAnythingRepository->editPrompt(\n $prompt,\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n } else {\n throw new InvalidArgumentException('Edit not allowed for prompt ' . $prompt->getUuid());\n }\n\n return new AskAnythingPromptDto(\n $newPrompt->getUuid(),\n $newPrompt->getTitle(),\n $newPrompt->getContent(),\n $newPrompt->getTarget(),\n $user->getUuid(),\n $shareUsersUuids,\n $shareGroupsUuids,\n );\n }\n\n public function delete(\n AskAnythingPrompt $prompt,\n User $user\n ): AskAnythingPrompt {\n if ($prompt->isDefaultPrompt()) {\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n } elseif ($prompt->getOwnerId() === $user->getId()) {\n $userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);\n $userPrompt?->delete();\n // For each relation, re-create the prompt for the receiver as their own\n $this->recreatePromptsForEachRelation($prompt);\n\n // Finally, delete the prompt\n $this->deletePromptIfNoRelations($prompt);\n } else {\n $userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);\n $groupPrompt = $this->askAnythingRepository->findSharedPromptByUserGroup($prompt->getId(), $user);\n\n // If the prompt is shared directly with the user, then \"unshare\" it\n if ($userPrompt instanceof UserAskAnythingPrompt && $groupPrompt === null) {\n $userPrompt->delete();\n $this->deletePromptIfNoRelations($prompt);\n } elseif ($groupPrompt instanceof UserAskAnythingPrompt) {\n // If the prompt is shared with the user and the group, then hide it for this user\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n } else {\n throw new InvalidArgumentException('Unknown delete allowance for prompt ' . $prompt->getUuid());\n }\n }\n\n return $prompt;\n }\n\n public function reorder(\n User $user,\n array $promptUuids,\n ): void {\n foreach ($promptUuids as $index => $promptUuid) {\n $prompt = $this->askAnythingRepository->getPromptByUuid($promptUuid);\n $this->askAnythingRepository->orderPromptForUser($prompt, $user, $index + 1);\n }\n }\n\n /**\n * @param AskAnythingPrompt $prompt\n *\n * @return array[array<string>, array<string>]\n */\n private function getReceiverUuids(AskAnythingPrompt $prompt): array\n {\n $shareUsers = [];\n $shareGroups = [];\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedUser = $sharedPrompt->getUser();\n if ($sharedUser instanceof User && $sharedUser->isStatusActive()) {\n $shareUsers[] = $sharedUser->getUuid();\n }\n $sharedGroup = $sharedPrompt->getGroup();\n if ($sharedGroup instanceof Group) {\n $shareGroups[] = $sharedGroup->getUuid();\n }\n }\n\n return [$shareUsers, $shareGroups];\n }\n\n private function deletePromptIfNoRelations(AskAnythingPrompt $prompt): void\n {\n if ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId())->isEmpty()) {\n // Disable and orphan any AutomatedReports that use this prompt\n $prompt->automatedReports()->withTrashed()->update([\n 'ask_anything_prompt_id' => null,\n 'status' => false,\n ]);\n\n // Delete only if there are no other relations to it.\n $this->askAnythingRepository->deletePrompt($prompt);\n }\n }\n\n private function recreatePromptsForEachRelation(AskAnythingPrompt $prompt): void\n {\n [$sharedUsersIds, $sharedUsersRemovedIds] = $this->recreatePromptsForUserRelations($prompt);\n $this->recreatePromptsForGroupRelations($prompt, $sharedUsersIds, $sharedUsersRemovedIds);\n }\n\n private function recreatePromptsForUserRelations(AskAnythingPrompt $prompt): array\n {\n $sharedUsersIds = [];\n $sharedUsersRemovedIds = [];\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedUser = $sharedPrompt->getUser();\n if ($sharedPrompt->isRemoved() === true) {\n $sharedUsersRemovedIds[] = $sharedUser->getId();\n }\n if ($sharedPrompt->isRemoved() !== true && $sharedUser instanceof User && $sharedUser->isStatusActive()) {\n $sharedUsersIds[] = $sharedUser->getId();\n $this->askAnythingRepository->createPrompt(\n $sharedUser,\n $prompt->getTarget(),\n $prompt->getTitle(),\n $prompt->getContent(),\n [],\n [],\n );\n $sharedPrompt->delete();\n }\n }\n\n return [$sharedUsersIds, $sharedUsersRemovedIds];\n }\n\n private function recreatePromptsForGroupRelations(AskAnythingPrompt $prompt, array $sharedUsersIds, array $sharedUsersRemovedIds): void\n {\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedGroup = $sharedPrompt->getGroup();\n if ($sharedGroup instanceof Group) {\n foreach ($sharedGroup->getMembers() as $member) {\n if (! in_array($member->getId(), $sharedUsersIds)\n && ! in_array($member->getId(), $sharedUsersRemovedIds)) {\n $sharedUsersIds[] = $member->getId();\n $this->askAnythingRepository->createPrompt(\n $member,\n $prompt->getTarget(),\n $prompt->getTitle(),\n $prompt->getContent(),\n [],\n [],\n );\n }\n }\n $sharedPrompt->delete();\n }\n }\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\AskAnything;\n\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\n\nclass AskAnythingPromptService\n{\n public function __construct(\n private readonly AskAnythingRepository $askAnythingRepository,\n private readonly UserRepository $userRepository,\n private readonly GroupRepositoryInterface $groupRepository,\n ) {\n }\n\n /**\n * @return array<AskAnythingPromptDto>\n */\n public function get(User $user, AskAnythingPromptTarget $target): array\n {\n $prompts = $this->askAnythingRepository->findPromptsByUserAndTarget(\n $user,\n $target\n );\n\n $promptDtos = [];\n foreach ($prompts as $prompt) {\n $ownerUuid = null;\n if ($prompt->getOwner() !== null) {\n $ownerUuid = $prompt->getOwner()->getUuid();\n }\n $shareUsers = null;\n $shareGroups = null;\n\n // Provide users and groups only if owner of the prompt is current user\n if ($prompt->getOwnerId() === $user->getId()) {\n [$shareUsers, $shareGroups] = $this->getReceiverUuids($prompt);\n }\n\n $promptDtos[] = new AskAnythingPromptDto(\n $prompt->getUuid(),\n $prompt->getTitle(),\n $prompt->getContent(),\n $target,\n $ownerUuid,\n $shareUsers,\n $shareGroups,\n $prompt->getHasReports(),\n );\n }\n\n return $promptDtos;\n }\n\n /**\n * @param array<string> $shareUsersUuids\n * @param array<string> $shareGroupsUuids\n */\n public function create(\n User $user,\n string $title,\n string $content,\n AskAnythingPromptTarget $target,\n array $shareUsersUuids,\n array $shareGroupsUuids\n ): AskAnythingPromptDto {\n\n $shareUsers = $shareGroups = [];\n foreach ($shareUsersUuids as $userUuid) {\n $shareUsers[] = $this->userRepository->findByUuid($userUuid);\n }\n foreach ($shareGroupsUuids as $groupUuid) {\n $shareGroups[] = $this->groupRepository->findByUuid($groupUuid);\n }\n\n $prompt = $this->askAnythingRepository->createPrompt(\n $user,\n $target,\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n\n return new AskAnythingPromptDto(\n $prompt->getUuid(),\n $prompt->getTitle(),\n $prompt->getContent(),\n $target,\n $user->getUuid(),\n $shareUsersUuids,\n $shareGroupsUuids,\n );\n }\n\n /**\n * @param array<string> $shareUsersUuids\n * @param array<string> $shareGroupsUuids\n *\n * @throws InvalidArgumentException\n */\n public function edit(\n AskAnythingPrompt $prompt,\n User $user,\n string $title,\n string $content,\n array $shareUsersUuids,\n array $shareGroupsUuids\n ): AskAnythingPromptDto {\n $shareUsers = $shareGroups = [];\n foreach ($shareUsersUuids as $userUuid) {\n $shareUsers[] = $this->userRepository->findByUuid($userUuid);\n }\n foreach ($shareGroupsUuids as $groupUuid) {\n $shareGroups[] = $this->groupRepository->findByUuid($groupUuid);\n }\n\n if ($prompt->isDefaultPrompt()) {\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n\n $newPrompt = $this->askAnythingRepository->createPrompt(\n $user,\n $prompt->getTarget(),\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n } elseif ($prompt->getOwnerId() === $user->getId()) {\n $newPrompt = $this->askAnythingRepository->editPrompt(\n $prompt,\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n } else {\n throw new InvalidArgumentException('Edit not allowed for prompt ' . $prompt->getUuid());\n }\n\n return new AskAnythingPromptDto(\n $newPrompt->getUuid(),\n $newPrompt->getTitle(),\n $newPrompt->getContent(),\n $newPrompt->getTarget(),\n $user->getUuid(),\n $shareUsersUuids,\n $shareGroupsUuids,\n );\n }\n\n public function delete(\n AskAnythingPrompt $prompt,\n User $user\n ): AskAnythingPrompt {\n if ($prompt->isDefaultPrompt()) {\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n } elseif ($prompt->getOwnerId() === $user->getId()) {\n $userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);\n $userPrompt?->delete();\n // For each relation, re-create the prompt for the receiver as their own\n $this->recreatePromptsForEachRelation($prompt);\n\n // Finally, delete the prompt\n $this->deletePromptIfNoRelations($prompt);\n } else {\n $userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);\n $groupPrompt = $this->askAnythingRepository->findSharedPromptByUserGroup($prompt->getId(), $user);\n\n // If the prompt is shared directly with the user, then \"unshare\" it\n if ($userPrompt instanceof UserAskAnythingPrompt && $groupPrompt === null) {\n $userPrompt->delete();\n $this->deletePromptIfNoRelations($prompt);\n } elseif ($groupPrompt instanceof UserAskAnythingPrompt) {\n // If the prompt is shared with the user and the group, then hide it for this user\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n } else {\n throw new InvalidArgumentException('Unknown delete allowance for prompt ' . $prompt->getUuid());\n }\n }\n\n return $prompt;\n }\n\n public function reorder(\n User $user,\n array $promptUuids,\n ): void {\n foreach ($promptUuids as $index => $promptUuid) {\n $prompt = $this->askAnythingRepository->getPromptByUuid($promptUuid);\n $this->askAnythingRepository->orderPromptForUser($prompt, $user, $index + 1);\n }\n }\n\n /**\n * @param AskAnythingPrompt $prompt\n *\n * @return array[array<string>, array<string>]\n */\n private function getReceiverUuids(AskAnythingPrompt $prompt): array\n {\n $shareUsers = [];\n $shareGroups = [];\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedUser = $sharedPrompt->getUser();\n if ($sharedUser instanceof User && $sharedUser->isStatusActive()) {\n $shareUsers[] = $sharedUser->getUuid();\n }\n $sharedGroup = $sharedPrompt->getGroup();\n if ($sharedGroup instanceof Group) {\n $shareGroups[] = $sharedGroup->getUuid();\n }\n }\n\n return [$shareUsers, $shareGroups];\n }\n\n private function deletePromptIfNoRelations(AskAnythingPrompt $prompt): void\n {\n if ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId())->isEmpty()) {\n // Disable and orphan any AutomatedReports that use this prompt\n $prompt->automatedReports()->withTrashed()->update([\n 'ask_anything_prompt_id' => null,\n 'status' => false,\n ]);\n\n // Delete only if there are no other relations to it.\n $this->askAnythingRepository->deletePrompt($prompt);\n }\n }\n\n private function recreatePromptsForEachRelation(AskAnythingPrompt $prompt): void\n {\n [$sharedUsersIds, $sharedUsersRemovedIds] = $this->recreatePromptsForUserRelations($prompt);\n $this->recreatePromptsForGroupRelations($prompt, $sharedUsersIds, $sharedUsersRemovedIds);\n }\n\n private function recreatePromptsForUserRelations(AskAnythingPrompt $prompt): array\n {\n $sharedUsersIds = [];\n $sharedUsersRemovedIds = [];\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedUser = $sharedPrompt->getUser();\n if ($sharedPrompt->isRemoved() === true) {\n $sharedUsersRemovedIds[] = $sharedUser->getId();\n }\n if ($sharedPrompt->isRemoved() !== true && $sharedUser instanceof User && $sharedUser->isStatusActive()) {\n $sharedUsersIds[] = $sharedUser->getId();\n $this->askAnythingRepository->createPrompt(\n $sharedUser,\n $prompt->getTarget(),\n $prompt->getTitle(),\n $prompt->getContent(),\n [],\n [],\n );\n $sharedPrompt->delete();\n }\n }\n\n return [$sharedUsersIds, $sharedUsersRemovedIds];\n }\n\n private function recreatePromptsForGroupRelations(AskAnythingPrompt $prompt, array $sharedUsersIds, array $sharedUsersRemovedIds): void\n {\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedGroup = $sharedPrompt->getGroup();\n if ($sharedGroup instanceof Group) {\n foreach ($sharedGroup->getMembers() as $member) {\n if (! in_array($member->getId(), $sharedUsersIds)\n && ! in_array($member->getId(), $sharedUsersRemovedIds)) {\n $sharedUsersIds[] = $member->getId();\n $this->askAnythingRepository->createPrompt(\n $member,\n $prompt->getTarget(),\n $prompt->getTitle(),\n $prompt->getContent(),\n [],\n [],\n );\n }\n }\n $sharedPrompt->delete();\n }\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.7124335,"top":0.10055866,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.72140956,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7287234,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"bounds":{"left":0.4481383,"top":0.09736632,"width":0.29288563,"height":0.8818835},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-2158660446698055511
|
-8096454476836467202
|
visual_change
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\AskAnything;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
class AskAnythingPromptService
{
public function __construct(
private readonly AskAnythingRepository $askAnythingRepository,
private readonly UserRepository $userRepository,
private readonly GroupRepositoryInterface $groupRepository,
) {
}
/**
* @return array<AskAnythingPromptDto>
*/
public function get(User $user, AskAnythingPromptTarget $target): array
{
$prompts = $this->askAnythingRepository->findPromptsByUserAndTarget(
$user,
$target
);
$promptDtos = [];
foreach ($prompts as $prompt) {
$ownerUuid = null;
if ($prompt->getOwner() !== null) {
$ownerUuid = $prompt->getOwner()->getUuid();
}
$shareUsers = null;
$shareGroups = null;
// Provide users and groups only if owner of the prompt is current user
if ($prompt->getOwnerId() === $user->getId()) {
[$shareUsers, $shareGroups] = $this->getReceiverUuids($prompt);
}
$promptDtos[] = new AskAnythingPromptDto(
$prompt->getUuid(),
$prompt->getTitle(),
$prompt->getContent(),
$target,
$ownerUuid,
$shareUsers,
$shareGroups,
$prompt->getHasReports(),
);
}
return $promptDtos;
}
/**
* @param array<string> $shareUsersUuids
* @param array<string> $shareGroupsUuids
*/
public function create(
User $user,
string $title,
string $content,
AskAnythingPromptTarget $target,
array $shareUsersUuids,
array $shareGroupsUuids
): AskAnythingPromptDto {
$shareUsers = $shareGroups = [];
foreach ($shareUsersUuids as $userUuid) {
$shareUsers[] = $this->userRepository->findByUuid($userUuid);
}
foreach ($shareGroupsUuids as $groupUuid) {
$shareGroups[] = $this->groupRepository->findByUuid($groupUuid);
}
$prompt = $this->askAnythingRepository->createPrompt(
$user,
$target,
$title,
$content,
$shareUsers,
$shareGroups,
);
return new AskAnythingPromptDto(
$prompt->getUuid(),
$prompt->getTitle(),
$prompt->getContent(),
$target,
$user->getUuid(),
$shareUsersUuids,
$shareGroupsUuids,
);
}
/**
* @param array<string> $shareUsersUuids
* @param array<string> $shareGroupsUuids
*
* @throws InvalidArgumentException
*/
public function edit(
AskAnythingPrompt $prompt,
User $user,
string $title,
string $content,
array $shareUsersUuids,
array $shareGroupsUuids
): AskAnythingPromptDto {
$shareUsers = $shareGroups = [];
foreach ($shareUsersUuids as $userUuid) {
$shareUsers[] = $this->userRepository->findByUuid($userUuid);
}
foreach ($shareGroupsUuids as $groupUuid) {
$shareGroups[] = $this->groupRepository->findByUuid($groupUuid);
}
if ($prompt->isDefaultPrompt()) {
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
$newPrompt = $this->askAnythingRepository->createPrompt(
$user,
$prompt->getTarget(),
$title,
$content,
$shareUsers,
$shareGroups,
);
} elseif ($prompt->getOwnerId() === $user->getId()) {
$newPrompt = $this->askAnythingRepository->editPrompt(
$prompt,
$title,
$content,
$shareUsers,
$shareGroups,
);
} else {
throw new InvalidArgumentException('Edit not allowed for prompt ' . $prompt->getUuid());
}
return new AskAnythingPromptDto(
$newPrompt->getUuid(),
$newPrompt->getTitle(),
$newPrompt->getContent(),
$newPrompt->getTarget(),
$user->getUuid(),
$shareUsersUuids,
$shareGroupsUuids,
);
}
public function delete(
AskAnythingPrompt $prompt,
User $user
): AskAnythingPrompt {
if ($prompt->isDefaultPrompt()) {
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
} elseif ($prompt->getOwnerId() === $user->getId()) {
$userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);
$userPrompt?->delete();
// For each relation, re-create the prompt for the receiver as their own
$this->recreatePromptsForEachRelation($prompt);
// Finally, delete the prompt
$this->deletePromptIfNoRelations($prompt);
} else {
$userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);
$groupPrompt = $this->askAnythingRepository->findSharedPromptByUserGroup($prompt->getId(), $user);
// If the prompt is shared directly with the user, then "unshare" it
if ($userPrompt instanceof UserAskAnythingPrompt && $groupPrompt === null) {
$userPrompt->delete();
$this->deletePromptIfNoRelations($prompt);
} elseif ($groupPrompt instanceof UserAskAnythingPrompt) {
// If the prompt is shared with the user and the group, then hide it for this user
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
} else {
throw new InvalidArgumentException('Unknown delete allowance for prompt ' . $prompt->getUuid());
}
}
return $prompt;
}
public function reorder(
User $user,
array $promptUuids,
): void {
foreach ($promptUuids as $index => $promptUuid) {
$prompt = $this->askAnythingRepository->getPromptByUuid($promptUuid);
$this->askAnythingRepository->orderPromptForUser($prompt, $user, $index + 1);
}
}
/**
* @param AskAnythingPrompt $prompt
*
* @return array[array<string>, array<string>]
*/
private function getReceiverUuids(AskAnythingPrompt $prompt): array
{
$shareUsers = [];
$shareGroups = [];
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedUser = $sharedPrompt->getUser();
if ($sharedUser instanceof User && $sharedUser->isStatusActive()) {
$shareUsers[] = $sharedUser->getUuid();
}
$sharedGroup = $sharedPrompt->getGroup();
if ($sharedGroup instanceof Group) {
$shareGroups[] = $sharedGroup->getUuid();
}
}
return [$shareUsers, $shareGroups];
}
private function deletePromptIfNoRelations(AskAnythingPrompt $prompt): void
{
if ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId())->isEmpty()) {
// Disable and orphan any AutomatedReports that use this prompt
$prompt->automatedReports()->withTrashed()->update([
'ask_anything_prompt_id' => null,
'status' => false,
]);
// Delete only if there are no other relations to it.
$this->askAnythingRepository->deletePrompt($prompt);
}
}
private function recreatePromptsForEachRelation(AskAnythingPrompt $prompt): void
{
[$sharedUsersIds, $sharedUsersRemovedIds] = $this->recreatePromptsForUserRelations($prompt);
$this->recreatePromptsForGroupRelations($prompt, $sharedUsersIds, $sharedUsersRemovedIds);
}
private function recreatePromptsForUserRelations(AskAnythingPrompt $prompt): array
{
$sharedUsersIds = [];
$sharedUsersRemovedIds = [];
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedUser = $sharedPrompt->getUser();
if ($sharedPrompt->isRemoved() === true) {
$sharedUsersRemovedIds[] = $sharedUser->getId();
}
if ($sharedPrompt->isRemoved() !== true && $sharedUser instanceof User && $sharedUser->isStatusActive()) {
$sharedUsersIds[] = $sharedUser->getId();
$this->askAnythingRepository->createPrompt(
$sharedUser,
$prompt->getTarget(),
$prompt->getTitle(),
$prompt->getContent(),
[],
[],
);
$sharedPrompt->delete();
}
}
return [$sharedUsersIds, $sharedUsersRemovedIds];
}
private function recreatePromptsForGroupRelations(AskAnythingPrompt $prompt, array $sharedUsersIds, array $sharedUsersRemovedIds): void
{
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedGroup = $sharedPrompt->getGroup();
if ($sharedGroup instanceof Group) {
foreach ($sharedGroup->getMembers() as $member) {
if (! in_array($member->getId(), $sharedUsersIds)
&& ! in_array($member->getId(), $sharedUsersRemovedIds)) {
$sharedUsersIds[] = $member->getId();
$this->askAnythingRepository->createPrompt(
$member,
$prompt->getTarget(),
$prompt->getTitle(),
$prompt->getContent(),
[],
[],
);
}
}
$sharedPrompt->delete();
}
}
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56823
|
NULL
|
NULL
|
NULL
|
|
56826
|
1974
|
9
|
2026-05-19T08:27:44.425233+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179264425_m1.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\AskAnything;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
class AskAnythingPromptService
{
public function __construct(
private readonly AskAnythingRepository $askAnythingRepository,
private readonly UserRepository $userRepository,
private readonly GroupRepositoryInterface $groupRepository,
) {
}
/**
* @return array<AskAnythingPromptDto>
*/
public function get(User $user, AskAnythingPromptTarget $target): array
{
$prompts = $this->askAnythingRepository->findPromptsByUserAndTarget(
$user,
$target
);
$promptDtos = [];
foreach ($prompts as $prompt) {
$ownerUuid = null;
if ($prompt->getOwner() !== null) {
$ownerUuid = $prompt->getOwner()->getUuid();
}
$shareUsers = null;
$shareGroups = null;
// Provide users and groups only if owner of the prompt is current user
if ($prompt->getOwnerId() === $user->getId()) {
[$shareUsers, $shareGroups] = $this->getReceiverUuids($prompt);
}
$promptDtos[] = new AskAnythingPromptDto(
$prompt->getUuid(),
$prompt->getTitle(),
$prompt->getContent(),
$target,
$ownerUuid,
$shareUsers,
$shareGroups,
$prompt->getHasReports(),
);
}
return $promptDtos;
}
/**
* @param array<string> $shareUsersUuids
* @param array<string> $shareGroupsUuids
*/
public function create(
User $user,
string $title,
string $content,
AskAnythingPromptTarget $target,
array $shareUsersUuids,
array $shareGroupsUuids
): AskAnythingPromptDto {
$shareUsers = $shareGroups = [];
foreach ($shareUsersUuids as $userUuid) {
$shareUsers[] = $this->userRepository->findByUuid($userUuid);
}
foreach ($shareGroupsUuids as $groupUuid) {
$shareGroups[] = $this->groupRepository->findByUuid($groupUuid);
}
$prompt = $this->askAnythingRepository->createPrompt(
$user,
$target,
$title,
$content,
$shareUsers,
$shareGroups,
);
return new AskAnythingPromptDto(
$prompt->getUuid(),
$prompt->getTitle(),
$prompt->getContent(),
$target,
$user->getUuid(),
$shareUsersUuids,
$shareGroupsUuids,
);
}
/**
* @param array<string> $shareUsersUuids
* @param array<string> $shareGroupsUuids
*
* @throws InvalidArgumentException
*/
public function edit(
AskAnythingPrompt $prompt,
User $user,
string $title,
string $content,
array $shareUsersUuids,
array $shareGroupsUuids
): AskAnythingPromptDto {
$shareUsers = $shareGroups = [];
foreach ($shareUsersUuids as $userUuid) {
$shareUsers[] = $this->userRepository->findByUuid($userUuid);
}
foreach ($shareGroupsUuids as $groupUuid) {
$shareGroups[] = $this->groupRepository->findByUuid($groupUuid);
}
if ($prompt->isDefaultPrompt()) {
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
$newPrompt = $this->askAnythingRepository->createPrompt(
$user,
$prompt->getTarget(),
$title,
$content,
$shareUsers,
$shareGroups,
);
} elseif ($prompt->getOwnerId() === $user->getId()) {
$newPrompt = $this->askAnythingRepository->editPrompt(
$prompt,
$title,
$content,
$shareUsers,
$shareGroups,
);
} else {
throw new InvalidArgumentException('Edit not allowed for prompt ' . $prompt->getUuid());
}
return new AskAnythingPromptDto(
$newPrompt->getUuid(),
$newPrompt->getTitle(),
$newPrompt->getContent(),
$newPrompt->getTarget(),
$user->getUuid(),
$shareUsersUuids,
$shareGroupsUuids,
);
}
public function delete(
AskAnythingPrompt $prompt,
User $user
): AskAnythingPrompt {
if ($prompt->isDefaultPrompt()) {
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
} elseif ($prompt->getOwnerId() === $user->getId()) {
$userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);
$userPrompt?->delete();
// For each relation, re-create the prompt for the receiver as their own
$this->recreatePromptsForEachRelation($prompt);
// Finally, delete the prompt
$this->deletePromptIfNoRelations($prompt);
} else {
$userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);
$groupPrompt = $this->askAnythingRepository->findSharedPromptByUserGroup($prompt->getId(), $user);
// If the prompt is shared directly with the user, then "unshare" it
if ($userPrompt instanceof UserAskAnythingPrompt && $groupPrompt === null) {
$userPrompt->delete();
$this->deletePromptIfNoRelations($prompt);
} elseif ($groupPrompt instanceof UserAskAnythingPrompt) {
// If the prompt is shared with the user and the group, then hide it for this user
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
} else {
throw new InvalidArgumentException('Unknown delete allowance for prompt ' . $prompt->getUuid());
}
}
return $prompt;
}
public function reorder(
User $user,
array $promptUuids,
): void {
foreach ($promptUuids as $index => $promptUuid) {
$prompt = $this->askAnythingRepository->getPromptByUuid($promptUuid);
$this->askAnythingRepository->orderPromptForUser($prompt, $user, $index + 1);
}
}
/**
* @param AskAnythingPrompt $prompt
*
* @return array[array<string>, array<string>]
*/
private function getReceiverUuids(AskAnythingPrompt $prompt): array
{
$shareUsers = [];
$shareGroups = [];
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedUser = $sharedPrompt->getUser();
if ($sharedUser instanceof User && $sharedUser->isStatusActive()) {
$shareUsers[] = $sharedUser->getUuid();
}
$sharedGroup = $sharedPrompt->getGroup();
if ($sharedGroup instanceof Group) {
$shareGroups[] = $sharedGroup->getUuid();
}
}
return [$shareUsers, $shareGroups];
}
private function deletePromptIfNoRelations(AskAnythingPrompt $prompt): void
{
if ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId())->isEmpty()) {
// Disable and orphan any AutomatedReports that use this prompt
$prompt->automatedReports()->withTrashed()->update([
'ask_anything_prompt_id' => null,
'status' => false,
]);
// Delete only if there are no other relations to it.
$this->askAnythingRepository->deletePrompt($prompt);
}
}
private function recreatePromptsForEachRelation(AskAnythingPrompt $prompt): void
{
[$sharedUsersIds, $sharedUsersRemovedIds] = $this->recreatePromptsForUserRelations($prompt);
$this->recreatePromptsForGroupRelations($prompt, $sharedUsersIds, $sharedUsersRemovedIds);
}
private function recreatePromptsForUserRelations(AskAnythingPrompt $prompt): array
{
$sharedUsersIds = [];
$sharedUsersRemovedIds = [];
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedUser = $sharedPrompt->getUser();
if ($sharedPrompt->isRemoved() === true) {
$sharedUsersRemovedIds[] = $sharedUser->getId();
}
if ($sharedPrompt->isRemoved() !== true && $sharedUser instanceof User && $sharedUser->isStatusActive()) {
$sharedUsersIds[] = $sharedUser->getId();
$this->askAnythingRepository->createPrompt(
$sharedUser,
$prompt->getTarget(),
$prompt->getTitle(),
$prompt->getContent(),
[],
[],
);
$sharedPrompt->delete();
}
}
return [$sharedUsersIds, $sharedUsersRemovedIds];
}
private function recreatePromptsForGroupRelations(AskAnythingPrompt $prompt, array $sharedUsersIds, array $sharedUsersRemovedIds): void
{
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedGroup = $sharedPrompt->getGroup();
if ($sharedGroup instanceof Group) {
foreach ($sharedGroup->getMembers() as $member) {
if (! in_array($member->getId(), $sharedUsersIds)
&& ! in_array($member->getId(), $sharedUsersRemovedIds)) {
$sharedUsersIds[] = $member->getId();
$this->askAnythingRepository->createPrompt(
$member,
$prompt->getTarget(),
$prompt->getTitle(),
$prompt->getContent(),
[],
[],
);
}
}
$sharedPrompt->delete();
}
}
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"4","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.016666668,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.016666668,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\AskAnything;\n\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\n\nclass AskAnythingPromptService\n{\n public function __construct(\n private readonly AskAnythingRepository $askAnythingRepository,\n private readonly UserRepository $userRepository,\n private readonly GroupRepositoryInterface $groupRepository,\n ) {\n }\n\n /**\n * @return array<AskAnythingPromptDto>\n */\n public function get(User $user, AskAnythingPromptTarget $target): array\n {\n $prompts = $this->askAnythingRepository->findPromptsByUserAndTarget(\n $user,\n $target\n );\n\n $promptDtos = [];\n foreach ($prompts as $prompt) {\n $ownerUuid = null;\n if ($prompt->getOwner() !== null) {\n $ownerUuid = $prompt->getOwner()->getUuid();\n }\n $shareUsers = null;\n $shareGroups = null;\n\n // Provide users and groups only if owner of the prompt is current user\n if ($prompt->getOwnerId() === $user->getId()) {\n [$shareUsers, $shareGroups] = $this->getReceiverUuids($prompt);\n }\n\n $promptDtos[] = new AskAnythingPromptDto(\n $prompt->getUuid(),\n $prompt->getTitle(),\n $prompt->getContent(),\n $target,\n $ownerUuid,\n $shareUsers,\n $shareGroups,\n $prompt->getHasReports(),\n );\n }\n\n return $promptDtos;\n }\n\n /**\n * @param array<string> $shareUsersUuids\n * @param array<string> $shareGroupsUuids\n */\n public function create(\n User $user,\n string $title,\n string $content,\n AskAnythingPromptTarget $target,\n array $shareUsersUuids,\n array $shareGroupsUuids\n ): AskAnythingPromptDto {\n\n $shareUsers = $shareGroups = [];\n foreach ($shareUsersUuids as $userUuid) {\n $shareUsers[] = $this->userRepository->findByUuid($userUuid);\n }\n foreach ($shareGroupsUuids as $groupUuid) {\n $shareGroups[] = $this->groupRepository->findByUuid($groupUuid);\n }\n\n $prompt = $this->askAnythingRepository->createPrompt(\n $user,\n $target,\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n\n return new AskAnythingPromptDto(\n $prompt->getUuid(),\n $prompt->getTitle(),\n $prompt->getContent(),\n $target,\n $user->getUuid(),\n $shareUsersUuids,\n $shareGroupsUuids,\n );\n }\n\n /**\n * @param array<string> $shareUsersUuids\n * @param array<string> $shareGroupsUuids\n *\n * @throws InvalidArgumentException\n */\n public function edit(\n AskAnythingPrompt $prompt,\n User $user,\n string $title,\n string $content,\n array $shareUsersUuids,\n array $shareGroupsUuids\n ): AskAnythingPromptDto {\n $shareUsers = $shareGroups = [];\n foreach ($shareUsersUuids as $userUuid) {\n $shareUsers[] = $this->userRepository->findByUuid($userUuid);\n }\n foreach ($shareGroupsUuids as $groupUuid) {\n $shareGroups[] = $this->groupRepository->findByUuid($groupUuid);\n }\n\n if ($prompt->isDefaultPrompt()) {\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n\n $newPrompt = $this->askAnythingRepository->createPrompt(\n $user,\n $prompt->getTarget(),\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n } elseif ($prompt->getOwnerId() === $user->getId()) {\n $newPrompt = $this->askAnythingRepository->editPrompt(\n $prompt,\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n } else {\n throw new InvalidArgumentException('Edit not allowed for prompt ' . $prompt->getUuid());\n }\n\n return new AskAnythingPromptDto(\n $newPrompt->getUuid(),\n $newPrompt->getTitle(),\n $newPrompt->getContent(),\n $newPrompt->getTarget(),\n $user->getUuid(),\n $shareUsersUuids,\n $shareGroupsUuids,\n );\n }\n\n public function delete(\n AskAnythingPrompt $prompt,\n User $user\n ): AskAnythingPrompt {\n if ($prompt->isDefaultPrompt()) {\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n } elseif ($prompt->getOwnerId() === $user->getId()) {\n $userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);\n $userPrompt?->delete();\n // For each relation, re-create the prompt for the receiver as their own\n $this->recreatePromptsForEachRelation($prompt);\n\n // Finally, delete the prompt\n $this->deletePromptIfNoRelations($prompt);\n } else {\n $userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);\n $groupPrompt = $this->askAnythingRepository->findSharedPromptByUserGroup($prompt->getId(), $user);\n\n // If the prompt is shared directly with the user, then \"unshare\" it\n if ($userPrompt instanceof UserAskAnythingPrompt && $groupPrompt === null) {\n $userPrompt->delete();\n $this->deletePromptIfNoRelations($prompt);\n } elseif ($groupPrompt instanceof UserAskAnythingPrompt) {\n // If the prompt is shared with the user and the group, then hide it for this user\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n } else {\n throw new InvalidArgumentException('Unknown delete allowance for prompt ' . $prompt->getUuid());\n }\n }\n\n return $prompt;\n }\n\n public function reorder(\n User $user,\n array $promptUuids,\n ): void {\n foreach ($promptUuids as $index => $promptUuid) {\n $prompt = $this->askAnythingRepository->getPromptByUuid($promptUuid);\n $this->askAnythingRepository->orderPromptForUser($prompt, $user, $index + 1);\n }\n }\n\n /**\n * @param AskAnythingPrompt $prompt\n *\n * @return array[array<string>, array<string>]\n */\n private function getReceiverUuids(AskAnythingPrompt $prompt): array\n {\n $shareUsers = [];\n $shareGroups = [];\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedUser = $sharedPrompt->getUser();\n if ($sharedUser instanceof User && $sharedUser->isStatusActive()) {\n $shareUsers[] = $sharedUser->getUuid();\n }\n $sharedGroup = $sharedPrompt->getGroup();\n if ($sharedGroup instanceof Group) {\n $shareGroups[] = $sharedGroup->getUuid();\n }\n }\n\n return [$shareUsers, $shareGroups];\n }\n\n private function deletePromptIfNoRelations(AskAnythingPrompt $prompt): void\n {\n if ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId())->isEmpty()) {\n // Disable and orphan any AutomatedReports that use this prompt\n $prompt->automatedReports()->withTrashed()->update([\n 'ask_anything_prompt_id' => null,\n 'status' => false,\n ]);\n\n // Delete only if there are no other relations to it.\n $this->askAnythingRepository->deletePrompt($prompt);\n }\n }\n\n private function recreatePromptsForEachRelation(AskAnythingPrompt $prompt): void\n {\n [$sharedUsersIds, $sharedUsersRemovedIds] = $this->recreatePromptsForUserRelations($prompt);\n $this->recreatePromptsForGroupRelations($prompt, $sharedUsersIds, $sharedUsersRemovedIds);\n }\n\n private function recreatePromptsForUserRelations(AskAnythingPrompt $prompt): array\n {\n $sharedUsersIds = [];\n $sharedUsersRemovedIds = [];\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedUser = $sharedPrompt->getUser();\n if ($sharedPrompt->isRemoved() === true) {\n $sharedUsersRemovedIds[] = $sharedUser->getId();\n }\n if ($sharedPrompt->isRemoved() !== true && $sharedUser instanceof User && $sharedUser->isStatusActive()) {\n $sharedUsersIds[] = $sharedUser->getId();\n $this->askAnythingRepository->createPrompt(\n $sharedUser,\n $prompt->getTarget(),\n $prompt->getTitle(),\n $prompt->getContent(),\n [],\n [],\n );\n $sharedPrompt->delete();\n }\n }\n\n return [$sharedUsersIds, $sharedUsersRemovedIds];\n }\n\n private function recreatePromptsForGroupRelations(AskAnythingPrompt $prompt, array $sharedUsersIds, array $sharedUsersRemovedIds): void\n {\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedGroup = $sharedPrompt->getGroup();\n if ($sharedGroup instanceof Group) {\n foreach ($sharedGroup->getMembers() as $member) {\n if (! in_array($member->getId(), $sharedUsersIds)\n && ! in_array($member->getId(), $sharedUsersRemovedIds)) {\n $sharedUsersIds[] = $member->getId();\n $this->askAnythingRepository->createPrompt(\n $member,\n $prompt->getTarget(),\n $prompt->getTitle(),\n $prompt->getContent(),\n [],\n [],\n );\n }\n }\n $sharedPrompt->delete();\n }\n }\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\AskAnything;\n\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\n\nclass AskAnythingPromptService\n{\n public function __construct(\n private readonly AskAnythingRepository $askAnythingRepository,\n private readonly UserRepository $userRepository,\n private readonly GroupRepositoryInterface $groupRepository,\n ) {\n }\n\n /**\n * @return array<AskAnythingPromptDto>\n */\n public function get(User $user, AskAnythingPromptTarget $target): array\n {\n $prompts = $this->askAnythingRepository->findPromptsByUserAndTarget(\n $user,\n $target\n );\n\n $promptDtos = [];\n foreach ($prompts as $prompt) {\n $ownerUuid = null;\n if ($prompt->getOwner() !== null) {\n $ownerUuid = $prompt->getOwner()->getUuid();\n }\n $shareUsers = null;\n $shareGroups = null;\n\n // Provide users and groups only if owner of the prompt is current user\n if ($prompt->getOwnerId() === $user->getId()) {\n [$shareUsers, $shareGroups] = $this->getReceiverUuids($prompt);\n }\n\n $promptDtos[] = new AskAnythingPromptDto(\n $prompt->getUuid(),\n $prompt->getTitle(),\n $prompt->getContent(),\n $target,\n $ownerUuid,\n $shareUsers,\n $shareGroups,\n $prompt->getHasReports(),\n );\n }\n\n return $promptDtos;\n }\n\n /**\n * @param array<string> $shareUsersUuids\n * @param array<string> $shareGroupsUuids\n */\n public function create(\n User $user,\n string $title,\n string $content,\n AskAnythingPromptTarget $target,\n array $shareUsersUuids,\n array $shareGroupsUuids\n ): AskAnythingPromptDto {\n\n $shareUsers = $shareGroups = [];\n foreach ($shareUsersUuids as $userUuid) {\n $shareUsers[] = $this->userRepository->findByUuid($userUuid);\n }\n foreach ($shareGroupsUuids as $groupUuid) {\n $shareGroups[] = $this->groupRepository->findByUuid($groupUuid);\n }\n\n $prompt = $this->askAnythingRepository->createPrompt(\n $user,\n $target,\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n\n return new AskAnythingPromptDto(\n $prompt->getUuid(),\n $prompt->getTitle(),\n $prompt->getContent(),\n $target,\n $user->getUuid(),\n $shareUsersUuids,\n $shareGroupsUuids,\n );\n }\n\n /**\n * @param array<string> $shareUsersUuids\n * @param array<string> $shareGroupsUuids\n *\n * @throws InvalidArgumentException\n */\n public function edit(\n AskAnythingPrompt $prompt,\n User $user,\n string $title,\n string $content,\n array $shareUsersUuids,\n array $shareGroupsUuids\n ): AskAnythingPromptDto {\n $shareUsers = $shareGroups = [];\n foreach ($shareUsersUuids as $userUuid) {\n $shareUsers[] = $this->userRepository->findByUuid($userUuid);\n }\n foreach ($shareGroupsUuids as $groupUuid) {\n $shareGroups[] = $this->groupRepository->findByUuid($groupUuid);\n }\n\n if ($prompt->isDefaultPrompt()) {\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n\n $newPrompt = $this->askAnythingRepository->createPrompt(\n $user,\n $prompt->getTarget(),\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n } elseif ($prompt->getOwnerId() === $user->getId()) {\n $newPrompt = $this->askAnythingRepository->editPrompt(\n $prompt,\n $title,\n $content,\n $shareUsers,\n $shareGroups,\n );\n } else {\n throw new InvalidArgumentException('Edit not allowed for prompt ' . $prompt->getUuid());\n }\n\n return new AskAnythingPromptDto(\n $newPrompt->getUuid(),\n $newPrompt->getTitle(),\n $newPrompt->getContent(),\n $newPrompt->getTarget(),\n $user->getUuid(),\n $shareUsersUuids,\n $shareGroupsUuids,\n );\n }\n\n public function delete(\n AskAnythingPrompt $prompt,\n User $user\n ): AskAnythingPrompt {\n if ($prompt->isDefaultPrompt()) {\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n } elseif ($prompt->getOwnerId() === $user->getId()) {\n $userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);\n $userPrompt?->delete();\n // For each relation, re-create the prompt for the receiver as their own\n $this->recreatePromptsForEachRelation($prompt);\n\n // Finally, delete the prompt\n $this->deletePromptIfNoRelations($prompt);\n } else {\n $userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);\n $groupPrompt = $this->askAnythingRepository->findSharedPromptByUserGroup($prompt->getId(), $user);\n\n // If the prompt is shared directly with the user, then \"unshare\" it\n if ($userPrompt instanceof UserAskAnythingPrompt && $groupPrompt === null) {\n $userPrompt->delete();\n $this->deletePromptIfNoRelations($prompt);\n } elseif ($groupPrompt instanceof UserAskAnythingPrompt) {\n // If the prompt is shared with the user and the group, then hide it for this user\n $this->askAnythingRepository->hidePromptForUser($prompt, $user);\n } else {\n throw new InvalidArgumentException('Unknown delete allowance for prompt ' . $prompt->getUuid());\n }\n }\n\n return $prompt;\n }\n\n public function reorder(\n User $user,\n array $promptUuids,\n ): void {\n foreach ($promptUuids as $index => $promptUuid) {\n $prompt = $this->askAnythingRepository->getPromptByUuid($promptUuid);\n $this->askAnythingRepository->orderPromptForUser($prompt, $user, $index + 1);\n }\n }\n\n /**\n * @param AskAnythingPrompt $prompt\n *\n * @return array[array<string>, array<string>]\n */\n private function getReceiverUuids(AskAnythingPrompt $prompt): array\n {\n $shareUsers = [];\n $shareGroups = [];\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedUser = $sharedPrompt->getUser();\n if ($sharedUser instanceof User && $sharedUser->isStatusActive()) {\n $shareUsers[] = $sharedUser->getUuid();\n }\n $sharedGroup = $sharedPrompt->getGroup();\n if ($sharedGroup instanceof Group) {\n $shareGroups[] = $sharedGroup->getUuid();\n }\n }\n\n return [$shareUsers, $shareGroups];\n }\n\n private function deletePromptIfNoRelations(AskAnythingPrompt $prompt): void\n {\n if ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId())->isEmpty()) {\n // Disable and orphan any AutomatedReports that use this prompt\n $prompt->automatedReports()->withTrashed()->update([\n 'ask_anything_prompt_id' => null,\n 'status' => false,\n ]);\n\n // Delete only if there are no other relations to it.\n $this->askAnythingRepository->deletePrompt($prompt);\n }\n }\n\n private function recreatePromptsForEachRelation(AskAnythingPrompt $prompt): void\n {\n [$sharedUsersIds, $sharedUsersRemovedIds] = $this->recreatePromptsForUserRelations($prompt);\n $this->recreatePromptsForGroupRelations($prompt, $sharedUsersIds, $sharedUsersRemovedIds);\n }\n\n private function recreatePromptsForUserRelations(AskAnythingPrompt $prompt): array\n {\n $sharedUsersIds = [];\n $sharedUsersRemovedIds = [];\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedUser = $sharedPrompt->getUser();\n if ($sharedPrompt->isRemoved() === true) {\n $sharedUsersRemovedIds[] = $sharedUser->getId();\n }\n if ($sharedPrompt->isRemoved() !== true && $sharedUser instanceof User && $sharedUser->isStatusActive()) {\n $sharedUsersIds[] = $sharedUser->getId();\n $this->askAnythingRepository->createPrompt(\n $sharedUser,\n $prompt->getTarget(),\n $prompt->getTitle(),\n $prompt->getContent(),\n [],\n [],\n );\n $sharedPrompt->delete();\n }\n }\n\n return [$sharedUsersIds, $sharedUsersRemovedIds];\n }\n\n private function recreatePromptsForGroupRelations(AskAnythingPrompt $prompt, array $sharedUsersIds, array $sharedUsersRemovedIds): void\n {\n foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {\n $sharedGroup = $sharedPrompt->getGroup();\n if ($sharedGroup instanceof Group) {\n foreach ($sharedGroup->getMembers() as $member) {\n if (! in_array($member->getId(), $sharedUsersIds)\n && ! in_array($member->getId(), $sharedUsersRemovedIds)) {\n $sharedUsersIds[] = $member->getId();\n $this->askAnythingRepository->createPrompt(\n $member,\n $prompt->getTarget(),\n $prompt->getTitle(),\n $prompt->getContent(),\n [],\n [],\n );\n }\n }\n $sharedPrompt->delete();\n }\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-2158660446698055511
|
-8096454476836467202
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\AskAnything;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
class AskAnythingPromptService
{
public function __construct(
private readonly AskAnythingRepository $askAnythingRepository,
private readonly UserRepository $userRepository,
private readonly GroupRepositoryInterface $groupRepository,
) {
}
/**
* @return array<AskAnythingPromptDto>
*/
public function get(User $user, AskAnythingPromptTarget $target): array
{
$prompts = $this->askAnythingRepository->findPromptsByUserAndTarget(
$user,
$target
);
$promptDtos = [];
foreach ($prompts as $prompt) {
$ownerUuid = null;
if ($prompt->getOwner() !== null) {
$ownerUuid = $prompt->getOwner()->getUuid();
}
$shareUsers = null;
$shareGroups = null;
// Provide users and groups only if owner of the prompt is current user
if ($prompt->getOwnerId() === $user->getId()) {
[$shareUsers, $shareGroups] = $this->getReceiverUuids($prompt);
}
$promptDtos[] = new AskAnythingPromptDto(
$prompt->getUuid(),
$prompt->getTitle(),
$prompt->getContent(),
$target,
$ownerUuid,
$shareUsers,
$shareGroups,
$prompt->getHasReports(),
);
}
return $promptDtos;
}
/**
* @param array<string> $shareUsersUuids
* @param array<string> $shareGroupsUuids
*/
public function create(
User $user,
string $title,
string $content,
AskAnythingPromptTarget $target,
array $shareUsersUuids,
array $shareGroupsUuids
): AskAnythingPromptDto {
$shareUsers = $shareGroups = [];
foreach ($shareUsersUuids as $userUuid) {
$shareUsers[] = $this->userRepository->findByUuid($userUuid);
}
foreach ($shareGroupsUuids as $groupUuid) {
$shareGroups[] = $this->groupRepository->findByUuid($groupUuid);
}
$prompt = $this->askAnythingRepository->createPrompt(
$user,
$target,
$title,
$content,
$shareUsers,
$shareGroups,
);
return new AskAnythingPromptDto(
$prompt->getUuid(),
$prompt->getTitle(),
$prompt->getContent(),
$target,
$user->getUuid(),
$shareUsersUuids,
$shareGroupsUuids,
);
}
/**
* @param array<string> $shareUsersUuids
* @param array<string> $shareGroupsUuids
*
* @throws InvalidArgumentException
*/
public function edit(
AskAnythingPrompt $prompt,
User $user,
string $title,
string $content,
array $shareUsersUuids,
array $shareGroupsUuids
): AskAnythingPromptDto {
$shareUsers = $shareGroups = [];
foreach ($shareUsersUuids as $userUuid) {
$shareUsers[] = $this->userRepository->findByUuid($userUuid);
}
foreach ($shareGroupsUuids as $groupUuid) {
$shareGroups[] = $this->groupRepository->findByUuid($groupUuid);
}
if ($prompt->isDefaultPrompt()) {
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
$newPrompt = $this->askAnythingRepository->createPrompt(
$user,
$prompt->getTarget(),
$title,
$content,
$shareUsers,
$shareGroups,
);
} elseif ($prompt->getOwnerId() === $user->getId()) {
$newPrompt = $this->askAnythingRepository->editPrompt(
$prompt,
$title,
$content,
$shareUsers,
$shareGroups,
);
} else {
throw new InvalidArgumentException('Edit not allowed for prompt ' . $prompt->getUuid());
}
return new AskAnythingPromptDto(
$newPrompt->getUuid(),
$newPrompt->getTitle(),
$newPrompt->getContent(),
$newPrompt->getTarget(),
$user->getUuid(),
$shareUsersUuids,
$shareGroupsUuids,
);
}
public function delete(
AskAnythingPrompt $prompt,
User $user
): AskAnythingPrompt {
if ($prompt->isDefaultPrompt()) {
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
} elseif ($prompt->getOwnerId() === $user->getId()) {
$userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);
$userPrompt?->delete();
// For each relation, re-create the prompt for the receiver as their own
$this->recreatePromptsForEachRelation($prompt);
// Finally, delete the prompt
$this->deletePromptIfNoRelations($prompt);
} else {
$userPrompt = $this->askAnythingRepository->findSharedPromptByUser($prompt->getId(), $user);
$groupPrompt = $this->askAnythingRepository->findSharedPromptByUserGroup($prompt->getId(), $user);
// If the prompt is shared directly with the user, then "unshare" it
if ($userPrompt instanceof UserAskAnythingPrompt && $groupPrompt === null) {
$userPrompt->delete();
$this->deletePromptIfNoRelations($prompt);
} elseif ($groupPrompt instanceof UserAskAnythingPrompt) {
// If the prompt is shared with the user and the group, then hide it for this user
$this->askAnythingRepository->hidePromptForUser($prompt, $user);
} else {
throw new InvalidArgumentException('Unknown delete allowance for prompt ' . $prompt->getUuid());
}
}
return $prompt;
}
public function reorder(
User $user,
array $promptUuids,
): void {
foreach ($promptUuids as $index => $promptUuid) {
$prompt = $this->askAnythingRepository->getPromptByUuid($promptUuid);
$this->askAnythingRepository->orderPromptForUser($prompt, $user, $index + 1);
}
}
/**
* @param AskAnythingPrompt $prompt
*
* @return array[array<string>, array<string>]
*/
private function getReceiverUuids(AskAnythingPrompt $prompt): array
{
$shareUsers = [];
$shareGroups = [];
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedUser = $sharedPrompt->getUser();
if ($sharedUser instanceof User && $sharedUser->isStatusActive()) {
$shareUsers[] = $sharedUser->getUuid();
}
$sharedGroup = $sharedPrompt->getGroup();
if ($sharedGroup instanceof Group) {
$shareGroups[] = $sharedGroup->getUuid();
}
}
return [$shareUsers, $shareGroups];
}
private function deletePromptIfNoRelations(AskAnythingPrompt $prompt): void
{
if ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId())->isEmpty()) {
// Disable and orphan any AutomatedReports that use this prompt
$prompt->automatedReports()->withTrashed()->update([
'ask_anything_prompt_id' => null,
'status' => false,
]);
// Delete only if there are no other relations to it.
$this->askAnythingRepository->deletePrompt($prompt);
}
}
private function recreatePromptsForEachRelation(AskAnythingPrompt $prompt): void
{
[$sharedUsersIds, $sharedUsersRemovedIds] = $this->recreatePromptsForUserRelations($prompt);
$this->recreatePromptsForGroupRelations($prompt, $sharedUsersIds, $sharedUsersRemovedIds);
}
private function recreatePromptsForUserRelations(AskAnythingPrompt $prompt): array
{
$sharedUsersIds = [];
$sharedUsersRemovedIds = [];
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedUser = $sharedPrompt->getUser();
if ($sharedPrompt->isRemoved() === true) {
$sharedUsersRemovedIds[] = $sharedUser->getId();
}
if ($sharedPrompt->isRemoved() !== true && $sharedUser instanceof User && $sharedUser->isStatusActive()) {
$sharedUsersIds[] = $sharedUser->getId();
$this->askAnythingRepository->createPrompt(
$sharedUser,
$prompt->getTarget(),
$prompt->getTitle(),
$prompt->getContent(),
[],
[],
);
$sharedPrompt->delete();
}
}
return [$sharedUsersIds, $sharedUsersRemovedIds];
}
private function recreatePromptsForGroupRelations(AskAnythingPrompt $prompt, array $sharedUsersIds, array $sharedUsersRemovedIds): void
{
foreach ($this->askAnythingRepository->findSharedUsersAndGroupsByPromptId($prompt->getId()) as $sharedPrompt) {
$sharedGroup = $sharedPrompt->getGroup();
if ($sharedGroup instanceof Group) {
foreach ($sharedGroup->getMembers() as $member) {
if (! in_array($member->getId(), $sharedUsersIds)
&& ! in_array($member->getId(), $sharedUsersRemovedIds)) {
$sharedUsersIds[] = $member->getId();
$this->askAnythingRepository->createPrompt(
$member,
$prompt->getTarget(),
$prompt->getTitle(),
$prompt->getContent(),
[],
[],
);
}
}
$sharedPrompt->delete();
}
}
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
56827
|
1975
|
12
|
2026-05-19T08:27:54.886310+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179274886_m2.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
2
Previous Highlighted Error
Next Highlighted Error...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.098071806,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"4","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.007978723,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.007978723,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-1052939770409954743
|
-8132367147899573310
|
idle
|
hybrid
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
2
Previous Highlighted Error
Next Highlighted Error
PhostormVIewINavicarecodeKeractorWindowFV faVsco.js°9 JY-20676-delete-rProiectC ActivityController.ong© AskAnythingController.phpD AskAnything© AskAnythingPromptService.php X© AskAnythingPrompt.phpphp api_v2.phpvm Dtos© AutomatedReportsService.php© AskAnythingPromptDto.phpD eventsC) AskAnyth) search.phpAsKAnytningPromptservice.ongchistorvservice.ono0 AskJiminnyAiD AWSw cachew country1 Dataoase→ DatadogN DateTtimeN DealinsiahtsN DealRisksIM SlacticSearchM SloquentEncodingD EncryptionM Saken1 FeaturerlagsWrrMpegD FileSystemMconkoC GongC GuzzleHttpW KeyPointsW KIOSKDLoCKS2 MediaPioeline/ MobileSettinasIM Nudae1M Paragranh BreakerM PartitionedCookieM PlavbackPadeM PlavlistDronhotDronhotAfclass ASkAnyth1ngPromptServ1cepublic function get(User $user, AskAnythingPromptTarget $target): array$shareGroups = null;// Provide users and groups only if owner of the prompt is current usenit (sprompt->geruwnerso === suser->geclaoe[$shareUsers. SshareGroups] = Sthis->getReceiverUuids(Sprompt):Spromptdtos= new_Askanvth1ngPromptdtouSprompt->getuurdorSprompt->getintleolSprompt->getcontentoSpromot->aetHasRenortsolnetunn Snnomnthtas.* @panam array<string> $shareUsersUuids* coctan arrausstring> ssharebroupsuulaspublic function createduser suserstring StitleASkAnythingPromptlarget Starget.array SshareGroupsUuids): AskAnvthingPromptDtoSsharelsers = SshareGrouos =foreach ($sharellserslluids as Suserlluid) ≤Ssharellsers[] = Sthis->userRenositorv->findBvUuid($userluid)=ForpachSchareGrounslluids as SarounlluidhSchareGrounsi= Sthis->arounRenositorv->FindRvllu1dSacounlluzddeSprompt = Sthjs-easkAnytl Accept File se >gRatePfampte+ 3 of 3 files →es for other languages. (today 10:00)Accept Reject= custom.log= laravel.log4 SF jiminny@localhost]4 HS_local [jiminny@localhost]& console [PROD]# console [euyA console [STAGING]© CoachingFeedbackCoachUserln.php X<?phpA1. Ydeclare(scrict_cypes=l)nnamespace Jiminny Component Activ1tySearch Filterder1n1t1on:› use ...final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface29 Ф >34 0 >45 đ >118135136 ct ›146 đt ›151 C1usadeorivate const int No GROUP 10 = 9993 usagesorivate UserRenository SuserRenository:public function __construct(UserRepository $userRepository)f...hpublic function shouldApplyQueries: boolf...}public function getQueries: FilterDefinitionQueryCollection...hpublic function toArray@: array{...;private function getOptions(): array{...}public function getValue: array{...}private function getDefaultValue@: array{...}public function aetValidationRules(2strina Sorefix = null): arrav{...}public function aetSortOrder@: intf...}public function shouldBeIncluded(Team $team): bool{...}"suppont Dally • In 3n 33m100% 5• Tue 19 May 11:27:54AskJiminnyReportActivityServiceTest vCascadeASK Jiminny Report+0..seview it prin. 3 ask perreports property.What is there is no ask liminny report realted at all. Most of them will be withoutThouaht for 1skead searchlranstormer.onp and & oter tllesThouaht for 4sSearchTransformer.nhoNow rework the DTo: make hasRenorts nullable so has revorts is oniv included for the list endooint (not create/uodate),• AskAnythingPromptDto.php409 tokensRemove hacRenorts from create() and edit() DTOs (onlv included in list response)."AskAnvthinaPromotService.ohvThought for 6sIservicelest.ono #L44-223Thought for 1c)• AskAnythingPromptServiceTest.phpy. O8 tokondw* Reiect allAccent alliAsk anvthina (84L)+ @ Code Claude Qnus 1.7 MediumW Windsurf Teams 59:1 (20 chars)io 4 spaces...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
56828
|
1975
|
13
|
2026-05-19T08:28:00.909005+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179280909_m2.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptServiceTest.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.098071806,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
5803414936471392232
|
-8636765907853005370
|
visual_change
|
hybrid
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
code› D Auth© ActivityAskAnythinglest.pnp© ExportControllerRateLimitTest.phpc) rakerropnercllent.onp›_ Middleware> @ Requests.w Interactionsw JobsNotirications1 OrcanizationSettinasPlavlists|M RevositoriesM RulesN SavedSearchesYel SavedSearchCRUn FeatureTect nhnM SoarchD ServiceProviders_ leamsCustomerAoiFeature lest.oneQ#t DeactivateUserFeatureTest.php*i SilterScheduledMeetinasFeaturelest.one NudgeProcessingFeatureTest.php*iOraanizationRolesFeaturelest.ono(© PlanhatServiceFeatureTest.phgTeamRetentionPolicyFeatureTest.php@ UserOnboardFeatureTest.php> M Integration• _ Servicesa Stubsv UnitActionsActionitems,MActivitvDActivityAnalyticsM AiActivitvTvneM AiAutomationD AiCallScoring• M AckAnvthingl© HistoryServiceTest.phpM Ack liminnyA© AskAnythingController.phpAsKAnythingPrompt.pnpphp api_v2.php© AskAnythingPromptService.php©› AskAnythingPromptSerclass ASKAnyth1ngPromptServ1celest extends Testcasepublic function testGetAskAnythingPrompts(): void'getUuid')->WLLLReCUrn valu$defaultPrompt = $this->createMock( originalClassName: AskAnythingPrompt::class)$defaultPrompt->expects($this->onceO)mpt-›expects(Sthis->onceo)'aetContent')->wllReturnd valu'What was the overall sentiment of the customer durina the call2!):SdefaultPromot->exnects(Sthis->onceobiAccentReiect$promptOwnedByUser = Sthis->createMock(AskAnythingPrompt::class):PRNNNNNESnromn+0wnedRvllsen-eynectc/Sthic-eyactlv(2))lsnromntlwnedRvllsen-exnectc/Sthic->onceon->willReturn('uuid-1st-prompt'):$promptOwnedByUser->expects($this->once)omptuwnedByUser-›expects(sth1s->onceop->W1LLReturn('Test prompt'):->method('getid')SpromotOwnedBvUser->exoects(Sthis->onceo)->wil ReturnGb3->method('aetHasRenorts')Sdefaul +Promntindered?vllcen = Sthis->createMockAckAnvthinaPromnt.•clacc)*Sdefaul+Promn+0rdenedRullsen-seynects(Sthic-sonce()->willReturn(null);na preforB edis4v Accept File %,-3 X Reject File +4C)+ 4 of 4 files →jes. (today 10:00)= custom.log= laravel.log4 SF jiminny@localhost]4 HS_local [jiminny@localhost]& console [PROD]# console [euyA console [STAGING]© CoachingFeedbackCoachUserln.php X<?phpdeclare(scrict_cypes=l)nnamespace Jiminny Component Activ1tysearch Filterderin1tion› use ...final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface29 Ф >34 0 >45 đ >118135136 ct ›146 C151 C1usadeorivate const int No GROUP 10 = 999.3 usagesorivate UserRenository SuserRenository:public function__construct(UserRepository $userRepository)1...hpublic function shouldApplyQueries: boolf...}public function getQueries: FilterDefinitionQueryCollection{...hpublic function toArray@: array{...;private function getOptions(): array{...}public function getValue: array{...}private function getDefaultValue: array{...}public function aetValidationRules(2strina Sorefix = null): arrav{...}public function aetSortOrder@: intf...}public function shouldBeIncluded(Team $team): bool{...}"suppont Dally • In 3n 33m100% 5• Tue 19 May 11:28:00AskJiminnyReportActivityServiceTest vCascadeASK Jiminny Report+0 ..seview it prin. 3 ask perreports property.What is there is no ask liminny report realted at all. Most of them will be withoutThouaht for 1skead searchlranstormer.onp and & oter tllesThouaht for 4sSearchTransformer.nhoNow rework the DTo: make hasRenorts nullable so has revorts is oniv included for the list endooint (not create/uodate),• AskAnythingPromptDto.php409 tokensRemove hasRenorts from create() and edit() DTOs (onlv included in list response)."AskAnvthinaPromotService.ohvThought for 6sIservicelest.ono #L44-223Thought for 1c)AskAnythingPromptServiceTest.php+24 -2w4 files +36 -4>Ask anvthina (84L)+ @ Code Claude Qnus 1.7 Medium* Reiect allAccent alliWN Windsurf Toams 66-1UTF.8Po 4 spaces...
|
56827
|
NULL
|
NULL
|
NULL
|
|
56829
|
NULL
|
0
|
2026-05-19T08:28:06.944958+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179286944_m2.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptServiceTest.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.098071806,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.007978723,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.7124335,"top":0.10055866,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.72140956,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7287234,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"bounds":{"left":0.4481383,"top":0.09736632,"width":0.29288563,"height":0.8818835},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
1140439531069478179
|
-8755961741003010129
|
visual_change
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
56830
|
NULL
|
0
|
2026-05-19T08:28:14.678477+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179294678_m1.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptServiceTest.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.016666668,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
1140439531069478179
|
-8755961741003010129
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56826
|
NULL
|
NULL
|
NULL
|
|
56831
|
1977
|
0
|
2026-05-19T08:28:37.280775+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179317280_m2.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptServiceTest.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.098071806,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.007978723,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.7124335,"top":0.10055866,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.72140956,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7287234,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"bounds":{"left":0.4481383,"top":0.09736632,"width":0.29288563,"height":0.8818835},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
1140439531069478179
|
-8755961741003010129
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56829
|
NULL
|
NULL
|
NULL
|
|
56832
|
1976
|
0
|
2026-05-19T08:28:44.929062+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179324929_m1.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptServiceTest.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.016666668,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
1140439531069478179
|
-8755961741003010129
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
56833
|
1977
|
1
|
2026-05-19T08:29:07.582562+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179347582_m2.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptServiceTest.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.098071806,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.007978723,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.7124335,"top":0.10055866,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.72140956,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7287234,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"bounds":{"left":0.4481383,"top":0.09736632,"width":0.29288563,"height":0.8818835},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
1140439531069478179
|
-8755961741003010129
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56829
|
NULL
|
NULL
|
NULL
|
|
56834
|
1976
|
1
|
2026-05-19T08:29:15.199397+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179355199_m1.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptServiceTest.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.016666668,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
1140439531069478179
|
-8755961741003010129
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56832
|
NULL
|
NULL
|
NULL
|
|
56835
|
1977
|
2
|
2026-05-19T08:29:37.871382+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179377871_m2.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptServiceTest.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.098071806,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.007978723,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.7124335,"top":0.10055866,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.72140956,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7287234,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"bounds":{"left":0.4481383,"top":0.09736632,"width":0.29288563,"height":0.8818835},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
1140439531069478179
|
-8755961741003010129
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56829
|
NULL
|
NULL
|
NULL
|
|
56836
|
1976
|
2
|
2026-05-19T08:29:45.433083+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179385433_m1.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptServiceTest.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.016666668,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
1140439531069478179
|
-8755961741003010129
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56832
|
NULL
|
NULL
|
NULL
|
|
56837
|
1977
|
3
|
2026-05-19T08:30:08.144531+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179408144_m2.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptServiceTest.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.098071806,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.007978723,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.7124335,"top":0.10055866,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.72140956,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7287234,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"bounds":{"left":0.4481383,"top":0.09736632,"width":0.29288563,"height":0.8818835},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
1140439531069478179
|
-8755961741003010129
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56829
|
NULL
|
NULL
|
NULL
|
|
56838
|
1976
|
3
|
2026-05-19T08:30:15.686628+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179415686_m1.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptServiceTest.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.016666668,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-7444542537786818265
|
-9057702366289408081
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}...
|
56832
|
NULL
|
NULL
|
NULL
|
|
56839
|
1977
|
4
|
2026-05-19T08:30:38.418983+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179438418_m2.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptServiceTest.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.098071806,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.007978723,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.7124335,"top":0.10055866,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.72140956,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7287234,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"bounds":{"left":0.4481383,"top":0.09736632,"width":0.29288563,"height":0.8818835},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
1140439531069478179
|
-8755961741003010129
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56829
|
NULL
|
NULL
|
NULL
|
|
56840
|
1976
|
4
|
2026-05-19T08:30:45.910054+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179445910_m1.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptServiceTest.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.016666668,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
1140439531069478179
|
-8755961741003010129
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
56841
|
1977
|
5
|
2026-05-19T08:31:08.734747+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179468734_m2.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptServiceTest.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.098071806,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.007978723,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.7124335,"top":0.10055866,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.72140956,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7287234,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"bounds":{"left":0.4481383,"top":0.09736632,"width":0.29288563,"height":0.8818835},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
1140439531069478179
|
-8755961741003010129
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56829
|
NULL
|
NULL
|
NULL
|
|
56842
|
1976
|
5
|
2026-05-19T08:31:16.132830+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179476132_m1.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptServiceTest.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.016666668,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
1140439531069478179
|
-8755961741003010129
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56840
|
NULL
|
NULL
|
NULL
|
|
56843
|
1977
|
6
|
2026-05-19T08:31:39.057161+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179499057_m2.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptServiceTest.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.098071806,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.007978723,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.7124335,"top":0.10055866,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.72140956,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7287234,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"bounds":{"left":0.4481383,"top":0.09736632,"width":0.29288563,"height":0.8818835},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
1140439531069478179
|
-8755961741003010129
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56829
|
NULL
|
NULL
|
NULL
|
|
56844
|
1976
|
6
|
2026-05-19T08:31:46.386029+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179506386_m1.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptServiceTest.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.016666668,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
1140439531069478179
|
-8755961741003010129
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56840
|
NULL
|
NULL
|
NULL
|
|
56845
|
1977
|
7
|
2026-05-19T08:32:09.398565+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179529398_m2.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptServiceTest.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.098071806,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.007978723,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.7124335,"top":0.10055866,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.72140956,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7287234,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"bounds":{"left":0.4481383,"top":0.09736632,"width":0.29288563,"height":0.8818835},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
1140439531069478179
|
-8755961741003010129
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56829
|
NULL
|
NULL
|
NULL
|
|
56846
|
1976
|
7
|
2026-05-19T08:32:16.618614+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179536618_m1.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptServiceTest.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.016666668,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
1140439531069478179
|
-8755961741003010129
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56840
|
NULL
|
NULL
|
NULL
|
|
56847
|
1977
|
8
|
2026-05-19T08:32:39.777311+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179559777_m2.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptServiceTest.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.098071806,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.007978723,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.7124335,"top":0.10055866,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.72140956,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7287234,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"bounds":{"left":0.4481383,"top":0.09736632,"width":0.29288563,"height":0.8818835},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
1140439531069478179
|
-8755961741003010129
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56829
|
NULL
|
NULL
|
NULL
|
|
56848
|
1976
|
8
|
2026-05-19T08:32:46.836378+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179566836_m1.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptServiceTest.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.016666668,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
1140439531069478179
|
-8755961741003010129
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56840
|
NULL
|
NULL
|
NULL
|
|
56849
|
NULL
|
0
|
2026-05-19T08:33:10.107253+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179590107_m2.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptServiceTest.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.098071806,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.007978723,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.7124335,"top":0.10055866,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.72140956,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7287234,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"bounds":{"left":0.4481383,"top":0.09736632,"width":0.29288563,"height":0.8818835},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
1140439531069478179
|
-8755961741003010129
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56829
|
NULL
|
NULL
|
NULL
|
|
56850
|
NULL
|
0
|
2026-05-19T08:33:17.074008+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179597074_m1.jpg...
|
PhpStorm
|
faVsco.js – AskAnythingPromptServiceTest.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.016666668,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Component\\AskAnything;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Contracts\\Repositories\\GroupRepositoryInterface;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AskAnything\\UserAskAnythingPrompt;\nuse Jiminny\\Models\\Group;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\UserRepository;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass AskAnythingPromptServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n private AskAnythingPromptService $askAnythingPromptService;\n private AskAnythingRepository&MockObject $askAnythingRepository;\n private UserRepository&MockObject $userRepository;\n private GroupRepositoryInterface&MockObject $groupRepository;\n\n protected function setUp(): void\n {\n $this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);\n $this->userRepository = $this->createMock(UserRepository::class);\n $this->groupRepository = $this->createMock(GroupRepositoryInterface::class);\n\n $this->askAnythingPromptService = new AskAnythingPromptService(\n $this->askAnythingRepository,\n $this->userRepository,\n $this->groupRepository\n );\n }\n\n public function testGetAskAnythingPrompts(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $user->expects($this->any())\n ->method('getUuid')\n ->willReturn('1');\n $defaultPrompt = $this->createMock(AskAnythingPrompt::class);\n $defaultPrompt->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPrompt->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUser->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('First users prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt');\n $promptOwnedByUser->expects($this->once())\n ->method('getId')\n ->willReturn(99);\n $promptOwnedByUser->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(true);\n $defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getOwner')\n ->willReturn(null);\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getUuid')\n ->willReturn('default-uuid');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getTitle')\n ->willReturn('Sentiment');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getContent')\n ->willReturn('What was the overall sentiment of the customer during the call?');\n $defaultPromptOrderedByUser->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n $promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);\n $promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))\n ->method('getOwner')\n ->willReturn($user);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-2nd-prompt');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getTitle')\n ->willReturn('Prompt shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getContent')\n ->willReturn('Test prompt that is shared with group');\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getId')\n ->willReturn(109);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $promptOwnedByUserAndSharedWithGroup->expects($this->once())\n ->method('getHasReports')\n ->willReturn(false);\n\n $group = $this->createMock(Group::class);\n $group->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-group');\n $sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);\n $sharedWithGroup->expects($this->once())\n ->method('getUser')\n ->willReturn(null);\n $sharedWithGroup->expects($this->once())\n ->method('getGroup')\n ->willReturn($group);\n\n $this->askAnythingRepository->expects($this->exactly(2))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [99, new Collection([])],\n [109, new Collection([$sharedWithGroup])],\n ]);\n\n $prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];\n $this->askAnythingRepository->expects($this->once())\n ->method('findPromptsByUserAndTarget')\n ->willReturn(new Collection($prompts));\n\n $expectedDto1 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto2 = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n 'First users prompt',\n 'Test prompt',\n AskAnythingPromptTarget::call,\n '1',\n [],\n [],\n true,\n );\n $expectedDto3 = new AskAnythingPromptDto(\n 'default-uuid',\n 'Sentiment',\n 'What was the overall sentiment of the customer during the call?',\n AskAnythingPromptTarget::call,\n null,\n null,\n null,\n false,\n );\n $expectedDto4 = new AskAnythingPromptDto(\n 'uuid-2nd-prompt',\n 'Prompt shared with group',\n 'Test prompt that is shared with group',\n AskAnythingPromptTarget::call,\n '1',\n [],\n ['uuid-of-the-group'],\n false,\n );\n $dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);\n\n $this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);\n }\n\n public function testEditAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(123);\n $prompt->expects($this->never())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('owner-uuid');\n\n $title = 'new title';\n $content = 'new content';\n $shareUsers = ['us-1'];\n $shareGroups = ['gr-1', 'gr-2'];\n\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $shareGroup1 = $this->createMock(Group::class);\n $shareGroup2 = $this->createMock(Group::class);\n $this->groupRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['gr-1', $shareGroup1],\n ['gr-2', $shareGroup2],\n ]);\n\n $editPrompt = $this->createMock(AskAnythingPrompt::class);\n $editPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $editPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $editPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $editPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $this->askAnythingRepository->expects($this->once())\n ->method('editPrompt')\n ->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])\n ->willReturn($editPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'owner-uuid',\n $shareUsers,\n $shareGroups\n );\n $editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $editDto);\n }\n\n public function testHideDefaultAndCreateAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('new-owner-uuid');\n $title = 'title';\n $content = 'content';\n $shareUsers = ['us-1'];\n $shareGroups = [];\n $shareUser = $this->createMock(User::class);\n $this->userRepository->expects($this->once())\n ->method('findByUuid')\n ->with('us-1')\n ->willReturn($shareUser);\n $this->groupRepository->expects($this->never())\n ->method('findByUuid');\n\n $newPrompt = $this->createMock(AskAnythingPrompt::class);\n $newPrompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $newPrompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-1st-prompt');\n $newPrompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $newPrompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->willReturn($newPrompt);\n\n $expectedDto = new AskAnythingPromptDto(\n 'uuid-1st-prompt',\n $title,\n $content,\n AskAnythingPromptTarget::call,\n 'new-owner-uuid',\n $shareUsers,\n $shareGroups\n );\n\n $actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);\n\n $this->assertEquals($expectedDto, $actualDto);\n }\n\n public function testDeleteAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n\n // Use Mockery for the relationship mock (more flexible)\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->any())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([]));\n $this->askAnythingRepository->expects($this->once())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteAskAnythingPromptWithRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $user = $this->createMock(User::class);\n $user->expects($this->any())\n ->method('getId')\n ->willReturn(1);\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(1, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('findSharedUsersAndGroupsByPromptId')\n ->willReturnMap([\n [1, new Collection([$userPrompt])],\n [1, new Collection([])],\n ]);\n $this->askAnythingRepository->expects($this->never())\n ->method('deletePrompt');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideDefaultAskAnythingPrompt(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(true);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser');\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(3))\n ->method('getId')\n ->willReturn(33);\n\n $relationMock = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $relationMock->shouldReceive('withTrashed')\n ->once()\n ->andReturnSelf();\n $relationMock->shouldReceive('update')\n ->once()\n ->with(['ask_anything_prompt_id' => null, 'status' => false]);\n $prompt->expects($this->once())\n ->method('automatedReports')\n ->willReturn($relationMock);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->once())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(33)\n ->willReturn(new Collection([]));\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testHideSharedWithGroupAskAnythingPrompt(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn($userPrompt);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->once())\n ->method('hidePromptForUser')\n ->with($prompt, $user);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testDeleteWithNoSharesAndNotOwner(): void\n {\n $userPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('isDefaultPrompt')\n ->willReturn(false);\n $prompt->expects($this->once())\n ->method('getOwnerId')\n ->willReturn(1);\n $prompt->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(33);\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(2);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUser')\n ->with(33, $user)\n ->willReturn(null);\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedPromptByUserGroup')\n ->with(33, $user)\n ->willReturn(null);\n $userPrompt->expects($this->never())\n ->method('delete');\n $this->askAnythingRepository->expects($this->never())\n ->method('hidePromptForUser');\n\n $this->expectException(\\InvalidArgumentException::class);\n\n $this->askAnythingPromptService->delete($prompt, $user);\n }\n\n public function testReorderAskAnythingPrompts(): void\n {\n $prompts = ['id1', 'id2', 'id3'];\n $prompt1 = $this->createMock(AskAnythingPrompt::class);\n $prompt2 = $this->createMock(AskAnythingPrompt::class);\n $prompt3 = $this->createMock(AskAnythingPrompt::class);\n $user = $this->createMock(User::class);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('getPromptByUuid')\n ->willReturnMap([\n ['id1', $prompt1],\n ['id2', $prompt2],\n ['id3', $prompt3],\n ]);\n $this->askAnythingRepository->expects($this->exactly(3))\n ->method('orderPromptForUser')\n ->willReturnMap([\n [[$prompt1, $user, 1]],\n [[$prompt2, $user, 2]],\n [[$prompt3, $user, 3]],\n ]);\n $this->askAnythingPromptService->reorder($user, $prompts);\n }\n\n public function testCreateAskAnythingPromptWithTwoUsers(): void\n {\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getUuid')\n ->willReturn('uuid-of-the-user');\n $shareUser1 = $this->createMock(User::class);\n $shareUser2 = $this->createMock(User::class);\n $title = 'Test title';\n $content = 'Test content';\n $target = AskAnythingPromptTarget::call;\n $shareUsers = ['us-1', 'us-2'];\n $shareGroups = [];\n\n $this->userRepository->expects($this->exactly(2))\n ->method('findByUuid')\n ->willReturnMap([\n ['us-1', $shareUser1],\n ['us-2', $shareUser2],\n ]);\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getUuid')\n ->willReturn('prompt-1-uuid');\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn($title);\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn($content);\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt')\n ->with(\n $user,\n $target,\n $title,\n $content,\n [$shareUser1, $shareUser2],\n [],\n )\n ->willReturn($prompt);\n\n $expectedPromptDto = new AskAnythingPromptDto(\n 'prompt-1-uuid',\n $title,\n $content,\n $target,\n 'uuid-of-the-user',\n $shareUsers,\n $shareGroups,\n );\n\n $actualPromptDto = $this->askAnythingPromptService->create(\n $user,\n $title,\n $content,\n $target,\n $shareUsers,\n $shareGroups\n );\n\n $this->assertEquals($expectedPromptDto, $actualPromptDto);\n }\n\n public function testRecreatePromptsForUserRelations(): void\n {\n $prompt = $this->createMock(AskAnythingPrompt::class);\n $prompt->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n $prompt->expects($this->once())\n ->method('getTarget')\n ->willReturn(AskAnythingPromptTarget::call);\n $prompt->expects($this->once())\n ->method('getTitle')\n ->willReturn('Test title');\n $prompt->expects($this->once())\n ->method('getContent')\n ->willReturn('Test content');\n\n $sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);\n $sharedUser = $this->createMock(User::class);\n $sharedUser->expects($this->once())\n ->method('isStatusActive')\n ->willReturn(true);\n $sharedUser->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $sharedPrompt->expects($this->once())\n ->method('getUser')\n ->willReturn($sharedUser);\n $sharedPrompt->expects($this->exactly(2))\n ->method('isRemoved')\n ->willReturn(false);\n $sharedPrompt->expects($this->once())\n ->method('delete');\n\n $this->askAnythingRepository->expects($this->once())\n ->method('findSharedUsersAndGroupsByPromptId')\n ->with(1)\n ->willReturn(new Collection([$sharedPrompt]));\n\n $this->askAnythingRepository->expects($this->once())\n ->method('createPrompt');\n\n $data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);\n\n $this->assertEquals([[1], []], $data);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
1140439531069478179
|
-8755961741003010129
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
6
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Component\AskAnything;
use Illuminate\Database\Eloquent\Collection;
use Jiminny\Component\AskAnything\AskAnythingPromptService;
use Jiminny\Component\AskAnything\Dtos\AskAnythingPromptDto;
use Jiminny\Contracts\Repositories\GroupRepositoryInterface;
use Jiminny\Models\AskAnything\AskAnythingPrompt;
use Jiminny\Models\AskAnything\AskAnythingPromptTarget;
use Jiminny\Models\AskAnything\UserAskAnythingPrompt;
use Jiminny\Models\Group;
use Jiminny\Models\User;
use Jiminny\Repositories\AskAnythingRepository;
use Jiminny\Repositories\UserRepository;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class AskAnythingPromptServiceTest extends TestCase
{
use TestPrivateMethod;
private AskAnythingPromptService $askAnythingPromptService;
private AskAnythingRepository&MockObject $askAnythingRepository;
private UserRepository&MockObject $userRepository;
private GroupRepositoryInterface&MockObject $groupRepository;
protected function setUp(): void
{
$this->askAnythingRepository = $this->createMock(AskAnythingRepository::class);
$this->userRepository = $this->createMock(UserRepository::class);
$this->groupRepository = $this->createMock(GroupRepositoryInterface::class);
$this->askAnythingPromptService = new AskAnythingPromptService(
$this->askAnythingRepository,
$this->userRepository,
$this->groupRepository
);
}
public function testGetAskAnythingPrompts(): void
{
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$user->expects($this->any())
->method('getUuid')
->willReturn('1');
$defaultPrompt = $this->createMock(AskAnythingPrompt::class);
$defaultPrompt->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPrompt->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPrompt->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPrompt->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPrompt->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUser = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUser->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUser->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$promptOwnedByUser->expects($this->once())
->method('getTitle')
->willReturn('First users prompt');
$promptOwnedByUser->expects($this->once())
->method('getContent')
->willReturn('Test prompt');
$promptOwnedByUser->expects($this->once())
->method('getId')
->willReturn(99);
$promptOwnedByUser->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUser->expects($this->once())
->method('getHasReports')
->willReturn(true);
$defaultPromptOrderedByUser = $this->createMock(AskAnythingPrompt::class);
$defaultPromptOrderedByUser->expects($this->once())
->method('getOwner')
->willReturn(null);
$defaultPromptOrderedByUser->expects($this->once())
->method('getUuid')
->willReturn('default-uuid');
$defaultPromptOrderedByUser->expects($this->once())
->method('getTitle')
->willReturn('Sentiment');
$defaultPromptOrderedByUser->expects($this->once())
->method('getContent')
->willReturn('What was the overall sentiment of the customer during the call?');
$defaultPromptOrderedByUser->expects($this->once())
->method('getHasReports')
->willReturn(false);
$promptOwnedByUserAndSharedWithGroup = $this->createMock(AskAnythingPrompt::class);
$promptOwnedByUserAndSharedWithGroup->expects($this->exactly(2))
->method('getOwner')
->willReturn($user);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getUuid')
->willReturn('uuid-2nd-prompt');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getTitle')
->willReturn('Prompt shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getContent')
->willReturn('Test prompt that is shared with group');
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getId')
->willReturn(109);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$promptOwnedByUserAndSharedWithGroup->expects($this->once())
->method('getHasReports')
->willReturn(false);
$group = $this->createMock(Group::class);
$group->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-group');
$sharedWithGroup = $this->createMock(UserAskAnythingPrompt::class);
$sharedWithGroup->expects($this->once())
->method('getUser')
->willReturn(null);
$sharedWithGroup->expects($this->once())
->method('getGroup')
->willReturn($group);
$this->askAnythingRepository->expects($this->exactly(2))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[99, new Collection([])],
[109, new Collection([$sharedWithGroup])],
]);
$prompts = [$defaultPrompt, $promptOwnedByUser, $defaultPromptOrderedByUser, $promptOwnedByUserAndSharedWithGroup];
$this->askAnythingRepository->expects($this->once())
->method('findPromptsByUserAndTarget')
->willReturn(new Collection($prompts));
$expectedDto1 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto2 = new AskAnythingPromptDto(
'uuid-1st-prompt',
'First users prompt',
'Test prompt',
AskAnythingPromptTarget::call,
'1',
[],
[],
true,
);
$expectedDto3 = new AskAnythingPromptDto(
'default-uuid',
'Sentiment',
'What was the overall sentiment of the customer during the call?',
AskAnythingPromptTarget::call,
null,
null,
null,
false,
);
$expectedDto4 = new AskAnythingPromptDto(
'uuid-2nd-prompt',
'Prompt shared with group',
'Test prompt that is shared with group',
AskAnythingPromptTarget::call,
'1',
[],
['uuid-of-the-group'],
false,
);
$dtos = $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::call);
$this->assertEquals([$expectedDto1, $expectedDto2, $expectedDto3, $expectedDto4], $dtos);
}
public function testEditAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(123);
$prompt->expects($this->never())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$user->expects($this->once())
->method('getUuid')
->willReturn('owner-uuid');
$title = 'new title';
$content = 'new content';
$shareUsers = ['us-1'];
$shareGroups = ['gr-1', 'gr-2'];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$shareGroup1 = $this->createMock(Group::class);
$shareGroup2 = $this->createMock(Group::class);
$this->groupRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['gr-1', $shareGroup1],
['gr-2', $shareGroup2],
]);
$editPrompt = $this->createMock(AskAnythingPrompt::class);
$editPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$editPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$editPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$editPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$this->askAnythingRepository->expects($this->once())
->method('editPrompt')
->with($prompt, $title, $content, [$shareUser], [$shareGroup1, $shareGroup2])
->willReturn($editPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'owner-uuid',
$shareUsers,
$shareGroups
);
$editDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $editDto);
}
public function testHideDefaultAndCreateAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('new-owner-uuid');
$title = 'title';
$content = 'content';
$shareUsers = ['us-1'];
$shareGroups = [];
$shareUser = $this->createMock(User::class);
$this->userRepository->expects($this->once())
->method('findByUuid')
->with('us-1')
->willReturn($shareUser);
$this->groupRepository->expects($this->never())
->method('findByUuid');
$newPrompt = $this->createMock(AskAnythingPrompt::class);
$newPrompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$newPrompt->expects($this->once())
->method('getUuid')
->willReturn('uuid-1st-prompt');
$newPrompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$newPrompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->willReturn($newPrompt);
$expectedDto = new AskAnythingPromptDto(
'uuid-1st-prompt',
$title,
$content,
AskAnythingPromptTarget::call,
'new-owner-uuid',
$shareUsers,
$shareGroups
);
$actualDto = $this->askAnythingPromptService->edit($prompt, $user, $title, $content, $shareUsers, $shareGroups);
$this->assertEquals($expectedDto, $actualDto);
}
public function testDeleteAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
// Use Mockery for the relationship mock (more flexible)
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->any())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([]));
$this->askAnythingRepository->expects($this->once())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteAskAnythingPromptWithRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->any())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getId')
->willReturn(1);
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(1, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->exactly(3))
->method('findSharedUsersAndGroupsByPromptId')
->willReturnMap([
[1, new Collection([$userPrompt])],
[1, new Collection([])],
]);
$this->askAnythingRepository->expects($this->never())
->method('deletePrompt');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideDefaultAskAnythingPrompt(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(true);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser');
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(3))
->method('getId')
->willReturn(33);
$relationMock = \Mockery::mock(\Illuminate\Database\Eloquent\Relations\HasMany::class);
$relationMock->shouldReceive('withTrashed')
->once()
->andReturnSelf();
$relationMock->shouldReceive('update')
->once()
->with(['ask_anything_prompt_id' => null, 'status' => false]);
$prompt->expects($this->once())
->method('automatedReports')
->willReturn($relationMock);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(33)
->willReturn(new Collection([]));
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithUserAndGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn($userPrompt);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testHideSharedWithGroupAskAnythingPrompt(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn($userPrompt);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('hidePromptForUser')
->with($prompt, $user);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testDeleteWithNoSharesAndNotOwner(): void
{
$userPrompt = $this->createMock(UserAskAnythingPrompt::class);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('isDefaultPrompt')
->willReturn(false);
$prompt->expects($this->once())
->method('getOwnerId')
->willReturn(1);
$prompt->expects($this->exactly(2))
->method('getId')
->willReturn(33);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(2);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUser')
->with(33, $user)
->willReturn(null);
$this->askAnythingRepository->expects($this->once())
->method('findSharedPromptByUserGroup')
->with(33, $user)
->willReturn(null);
$userPrompt->expects($this->never())
->method('delete');
$this->askAnythingRepository->expects($this->never())
->method('hidePromptForUser');
$this->expectException(\InvalidArgumentException::class);
$this->askAnythingPromptService->delete($prompt, $user);
}
public function testReorderAskAnythingPrompts(): void
{
$prompts = ['id1', 'id2', 'id3'];
$prompt1 = $this->createMock(AskAnythingPrompt::class);
$prompt2 = $this->createMock(AskAnythingPrompt::class);
$prompt3 = $this->createMock(AskAnythingPrompt::class);
$user = $this->createMock(User::class);
$this->askAnythingRepository->expects($this->exactly(3))
->method('getPromptByUuid')
->willReturnMap([
['id1', $prompt1],
['id2', $prompt2],
['id3', $prompt3],
]);
$this->askAnythingRepository->expects($this->exactly(3))
->method('orderPromptForUser')
->willReturnMap([
[[$prompt1, $user, 1]],
[[$prompt2, $user, 2]],
[[$prompt3, $user, 3]],
]);
$this->askAnythingPromptService->reorder($user, $prompts);
}
public function testCreateAskAnythingPromptWithTwoUsers(): void
{
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getUuid')
->willReturn('uuid-of-the-user');
$shareUser1 = $this->createMock(User::class);
$shareUser2 = $this->createMock(User::class);
$title = 'Test title';
$content = 'Test content';
$target = AskAnythingPromptTarget::call;
$shareUsers = ['us-1', 'us-2'];
$shareGroups = [];
$this->userRepository->expects($this->exactly(2))
->method('findByUuid')
->willReturnMap([
['us-1', $shareUser1],
['us-2', $shareUser2],
]);
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getUuid')
->willReturn('prompt-1-uuid');
$prompt->expects($this->once())
->method('getTitle')
->willReturn($title);
$prompt->expects($this->once())
->method('getContent')
->willReturn($content);
$this->askAnythingRepository->expects($this->once())
->method('createPrompt')
->with(
$user,
$target,
$title,
$content,
[$shareUser1, $shareUser2],
[],
)
->willReturn($prompt);
$expectedPromptDto = new AskAnythingPromptDto(
'prompt-1-uuid',
$title,
$content,
$target,
'uuid-of-the-user',
$shareUsers,
$shareGroups,
);
$actualPromptDto = $this->askAnythingPromptService->create(
$user,
$title,
$content,
$target,
$shareUsers,
$shareGroups
);
$this->assertEquals($expectedPromptDto, $actualPromptDto);
}
public function testRecreatePromptsForUserRelations(): void
{
$prompt = $this->createMock(AskAnythingPrompt::class);
$prompt->expects($this->once())
->method('getId')
->willReturn(1);
$prompt->expects($this->once())
->method('getTarget')
->willReturn(AskAnythingPromptTarget::call);
$prompt->expects($this->once())
->method('getTitle')
->willReturn('Test title');
$prompt->expects($this->once())
->method('getContent')
->willReturn('Test content');
$sharedPrompt = $this->createMock(UserAskAnythingPrompt::class);
$sharedUser = $this->createMock(User::class);
$sharedUser->expects($this->once())
->method('isStatusActive')
->willReturn(true);
$sharedUser->expects($this->once())
->method('getId')
->willReturn(1);
$sharedPrompt->expects($this->once())
->method('getUser')
->willReturn($sharedUser);
$sharedPrompt->expects($this->exactly(2))
->method('isRemoved')
->willReturn(false);
$sharedPrompt->expects($this->once())
->method('delete');
$this->askAnythingRepository->expects($this->once())
->method('findSharedUsersAndGroupsByPromptId')
->with(1)
->willReturn(new Collection([$sharedPrompt]));
$this->askAnythingRepository->expects($this->once())
->method('createPrompt');
$data = $this->invokePrivateMethod('recreatePromptsForUserRelations', $this->askAnythingPromptService, [$prompt]);
$this->assertEquals([[1], []], $data);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56840
|
NULL
|
NULL
|
NULL
|
|
56852
|
1979
|
0
|
2026-05-19T08:33:37.787432+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179617787_m2.jpg...
|
PhpStorm
|
faVsco.js – ActivityController.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
code› D Auth© ActivityAskAnythinglest.pnp© ExportC code› D Auth© ActivityAskAnythinglest.pnp© ExportControllerRateLimitTest.phpc) rakerropnercllent.onp›_ Middleware> @ Requests.w InteractionsNotirications1 OrcanizationSettinasPlavlists|M RevositoriesM RulesN SavedSearchesYel SavedSearchCRUn FeatureTect nhnM SoarchD ServiceProvidersCustomerAoiFeature lest.one*i DeactivateUserFeaturelest.ono*i SilterScheduledMeetinasFeaturelest.one NudgeProcessingFeatureTest.php*iOraanizationRolesFeaturelest.ono(© PlanhatServiceFeatureTest.phg( TeamRetentionPolicyFeatureTest.php@ UserOnboardFeatureTest.php> M Integration• _ Servicesa StubsUnitActionsActionitems• MActivitDActivityAnalytics• AiActivityTypeM AiAutomationD AiCallScoringTM AckAnvthingAckAnvthinaDromntCorvicoTact nhn© HistoryServiceTest.phpM Ack liminnyA© AskAnythingController.phpAsKAnythingPrompt.pnpphp api_v2.phpAsKAnytingPromptserwice.on© AskAnythingFclass ASKAnyth1ngPromptServ1celest extends Testcasepublic function testGetAskAnythingPrompts(): voidgetUuid')->WLLLRECUrn Val$defaultPrompt = $this->createMock( originalClassName: AskAnythingPrompt::class)saerauucrrompt->expectssch1s->once->onceo)What was the overall sentiment of the customer during the call?');AccentReiectCnromntlwnedRvlicen = Sthic->crpateMock* oridinalClassName: AckAnvthinaPromnt.•clacc)•CRNNANNASnromn+0wnedRvllsen-sexnectc/Sthic->eyact1v/ count: 2)91snromntlwnedRvllsen-exnectc/Sthic-sonceo'uuid-1st-prompt'):Snnomn+0unodRullcon-Jovnonte/Cthic.songor)SpromptownedByUser->expects(Sth1s->onceop'getid')SpromotOwnedBvUser->exoects(Sthis->onceo)aetOwnerid')SdeFaul +PromntinderedRvlisen = Sthis->croateMockd oricinalClassName: AckAnvthinaPromnt.•class)*+ 4 of 4 files →ac (todav 10-001= custom.log= laravel.log« SF jiminny@localhost]4 HS_local [jiminny@localhost]& console [PROD]# console [euyA console [STAGING]© CoachingFeedbackCoachUserln.php X<?phpdeclare(scrict_cypes=l)nnamespace Jiminny Component Activ1tysearch Filterderin1tion› use ...final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface29 Ф >34 0 >45 đ >135136 ct ›146 C151 C1usadeorivate const int No GROUp 10 = 99913 usagesorivate UserRenository suserRenository:public function__construct(UserRepository $userRepository)1...hpublic function shouldApplyQueries: boolf...}public function getQueries: FilterDefinitionQueryCollection{...hpublic function toArray@: array{...hprivate function getOptions(): array{...}public function getValue®: array{...}private function getDefaultValue@: array{...}public function aetValidationRules(2strina Sorefix = null): arrav{...}public function aetSortOrder@: intf...}public function shouldBeIncluded(Team $team): bool{...}suppont Dally • In 3n 21m100% 5• Tue 19 May 11:33:37AskJiminnyReportActivityServiceTest -CascadeASk Jiminny Report M+0 ..AskAnythingPromptService.phpInought tor osReadAskAnvthinaPromotServicelest.0no # 44-223Thought for 1sAskAnythingPromptServiceTest.php+24 -2Summarv of Revisions1. Searchtiranstormer now emits has renortslSearchTransformer.nhn. 42-50_Searchtranstormer.php:42-50public tunction transtorm(search Ssearch): arrayreturn"Tilters = Sthis->getrilters(Ssearch),'has reports' => Ssearch->automatedReportso->existsoYou reverted the Sappends laccessor on the Search model ((correctlv — addina it would have caused unnecessary querieseverywhere the model is serialized). The flag now lives only in the transformer used by listActivitySearch.2. Rethought the prompt DTOYou're riaht - newlv-created and edited oromots will never have related reports, and most existina oromots won't have anv• Made AskAnythingPromptDto::ShasReports nullable ?bool ShasReports = null).• Onlv included it in toArravo when it is not null — same conditional pattern as ownerid / sharellsers / shareGrouos |• Removed it from create() and edit() DTO construction in AskAnythingPromptService - they always pass nothingnow. so create/undate responses won't include has renorts•In get(), it stays — calls $prompt->getHasReports() (your renamed accessor) so the list endpoint emits the flag.This way the per-row exists() query is onlv run when the list endooint is hit. never on createledit.3. Test uodateUpdated testGetAskAnythingPrompts in AskAnythingPromptServiceTest.php to mock getHasReports() on everyoromot mock and reflect the values (one true, three false ) in the expected DTOs. The existina testCreateAskAnvthinaPromptWithTwoUsers. testEditAskAnythingPrompt. etc. don't need changes - they already construct expected DTOswithout an 8th araument. which now matches the null default.G..l..4 files +36 -4 >Accent allAsk anvthina 884-L)<> Code Claude Qnus 1.7 MediumWN Windsurf Toams 66-1UTF.8io 4 spaces...
|
NULL
|
2609577385902610161
|
NULL
|
click
|
ocr
|
NULL
|
code› D Auth© ActivityAskAnythinglest.pnp© ExportC code› D Auth© ActivityAskAnythinglest.pnp© ExportControllerRateLimitTest.phpc) rakerropnercllent.onp›_ Middleware> @ Requests.w InteractionsNotirications1 OrcanizationSettinasPlavlists|M RevositoriesM RulesN SavedSearchesYel SavedSearchCRUn FeatureTect nhnM SoarchD ServiceProvidersCustomerAoiFeature lest.one*i DeactivateUserFeaturelest.ono*i SilterScheduledMeetinasFeaturelest.one NudgeProcessingFeatureTest.php*iOraanizationRolesFeaturelest.ono(© PlanhatServiceFeatureTest.phg( TeamRetentionPolicyFeatureTest.php@ UserOnboardFeatureTest.php> M Integration• _ Servicesa StubsUnitActionsActionitems• MActivitDActivityAnalytics• AiActivityTypeM AiAutomationD AiCallScoringTM AckAnvthingAckAnvthinaDromntCorvicoTact nhn© HistoryServiceTest.phpM Ack liminnyA© AskAnythingController.phpAsKAnythingPrompt.pnpphp api_v2.phpAsKAnytingPromptserwice.on© AskAnythingFclass ASKAnyth1ngPromptServ1celest extends Testcasepublic function testGetAskAnythingPrompts(): voidgetUuid')->WLLLRECUrn Val$defaultPrompt = $this->createMock( originalClassName: AskAnythingPrompt::class)saerauucrrompt->expectssch1s->once->onceo)What was the overall sentiment of the customer during the call?');AccentReiectCnromntlwnedRvlicen = Sthic->crpateMock* oridinalClassName: AckAnvthinaPromnt.•clacc)•CRNNANNASnromn+0wnedRvllsen-sexnectc/Sthic->eyact1v/ count: 2)91snromntlwnedRvllsen-exnectc/Sthic-sonceo'uuid-1st-prompt'):Snnomn+0unodRullcon-Jovnonte/Cthic.songor)SpromptownedByUser->expects(Sth1s->onceop'getid')SpromotOwnedBvUser->exoects(Sthis->onceo)aetOwnerid')SdeFaul +PromntinderedRvlisen = Sthis->croateMockd oricinalClassName: AckAnvthinaPromnt.•class)*+ 4 of 4 files →ac (todav 10-001= custom.log= laravel.log« SF jiminny@localhost]4 HS_local [jiminny@localhost]& console [PROD]# console [euyA console [STAGING]© CoachingFeedbackCoachUserln.php X<?phpdeclare(scrict_cypes=l)nnamespace Jiminny Component Activ1tysearch Filterderin1tion› use ...final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface29 Ф >34 0 >45 đ >135136 ct ›146 C151 C1usadeorivate const int No GROUp 10 = 99913 usagesorivate UserRenository suserRenository:public function__construct(UserRepository $userRepository)1...hpublic function shouldApplyQueries: boolf...}public function getQueries: FilterDefinitionQueryCollection{...hpublic function toArray@: array{...hprivate function getOptions(): array{...}public function getValue®: array{...}private function getDefaultValue@: array{...}public function aetValidationRules(2strina Sorefix = null): arrav{...}public function aetSortOrder@: intf...}public function shouldBeIncluded(Team $team): bool{...}suppont Dally • In 3n 21m100% 5• Tue 19 May 11:33:37AskJiminnyReportActivityServiceTest -CascadeASk Jiminny Report M+0 ..AskAnythingPromptService.phpInought tor osReadAskAnvthinaPromotServicelest.0no # 44-223Thought for 1sAskAnythingPromptServiceTest.php+24 -2Summarv of Revisions1. Searchtiranstormer now emits has renortslSearchTransformer.nhn. 42-50_Searchtranstormer.php:42-50public tunction transtorm(search Ssearch): arrayreturn"Tilters = Sthis->getrilters(Ssearch),'has reports' => Ssearch->automatedReportso->existsoYou reverted the Sappends laccessor on the Search model ((correctlv — addina it would have caused unnecessary querieseverywhere the model is serialized). The flag now lives only in the transformer used by listActivitySearch.2. Rethought the prompt DTOYou're riaht - newlv-created and edited oromots will never have related reports, and most existina oromots won't have anv• Made AskAnythingPromptDto::ShasReports nullable ?bool ShasReports = null).• Onlv included it in toArravo when it is not null — same conditional pattern as ownerid / sharellsers / shareGrouos |• Removed it from create() and edit() DTO construction in AskAnythingPromptService - they always pass nothingnow. so create/undate responses won't include has renorts•In get(), it stays — calls $prompt->getHasReports() (your renamed accessor) so the list endpoint emits the flag.This way the per-row exists() query is onlv run when the list endooint is hit. never on createledit.3. Test uodateUpdated testGetAskAnythingPrompts in AskAnythingPromptServiceTest.php to mock getHasReports() on everyoromot mock and reflect the values (one true, three false ) in the expected DTOs. The existina testCreateAskAnvthinaPromptWithTwoUsers. testEditAskAnythingPrompt. etc. don't need changes - they already construct expected DTOswithout an 8th araument. which now matches the null default.G..l..4 files +36 -4 >Accent allAsk anvthina 884-L)<> Code Claude Qnus 1.7 MediumWN Windsurf Toams 66-1UTF.8io 4 spaces...
|
56829
|
NULL
|
NULL
|
NULL
|
|
56851
|
1978
|
0
|
2026-05-19T08:33:37.800518+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179617800_m1.jpg...
|
PhpStorm
|
faVsco.js – ActivityController.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpAPPDOCKER• ₴1D SlackFileEditViewGoHistoryWindowHelpAPPDOCKER• ₴1DEV (-zsh)₴82app/Jobs/Crm/MatchActivityCrmData.phpapp/Jobs/Middleware/HandleHubspotRateLimit.phpAPP (-zst47++++++p42++++++*app/Mcp/Servers/JiminnyServer.phpapp/Mcp/Tools/GetMeTool.php157++++++•app/Models/Feature/FeatureEnum.phpapp/Services/Activity/HubSpot/ProviderResolver.php+-app/Services/Activity/HubSpot/ProviderResolverInterface.phpapp/Services/Activity/HubSpot/Providers/Provider.phpapp/Services/Activity/HubSpot/Providers/ProviderKixie.php+-app/Services/Activity/HubSpot/Providers/Provider0rum.phpapp/Services/Activity/HubSpot/Providers/ProviderTwilio.phpapp/Services/Activity/HubSpot/Providers/ProviderTwilioFlex.phpapp/Services/Activity/HubSpot/Service.phpapp/Services/Crm/Hubspot/Client.phpapp/Services/Crm/Hubspot/HubspotClientInterface.phpapp/Services/Crm/Hubspot/Pagination/HubspotPaginationService.phpapp/Services/Crm/Hubspot/Pagination/PaginationState.phpdatabase/migrations/2026_05_13_124153_create_mcp_feature_flag.phptests/Feature/Mcp/GetMeToolFeatureTest.phptests/Feature/Mcp/ListCallsToolFeatureTest.phptests/Feature/Mcp/McpTestHelpersTrait.phptests/Unit/Component/ES/ChunkSizeTest.phptests/Unit/Component/ES/Processor/DT0s/SelectionListTest.phptests/Unit/Component/ES/Processor/TargetEntitiesSelectorTest.phptests/Unit/Component/MeetingBot/Service/ParticipantMatcherTest.phptests/Unit/Exceptions/RateLimitExceptionTest.phptests/Unit/Jobs/Crm/MatchActivityCrmDataTest.phptests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.phptests/Unit/Services/Activity/HubSpot/ServiceTest.phptests/Unit/Services/Crm/Hubspot/ClientTest.phptests/Unit/Services/Crm/Hubspot/Pagination/HubspotPaginationServiceTest.php97++++++-132++++++•15++++++21++++--2+-25++++++.140++++++•2+-19++++++50++++++-27++++++-39++++++-6856++++++-+-151++++++-109++++++-250++++++-283++++++=37 files changed, 1587 insertions(+), 344 deletions(-)create mode 100644 app/Component/ES/ChunkSize.phpcreate mode 100644 app/Jobs/Middleware/HandleHubspotRateLimit.phpcreate mode 100644 app/Mcp/Tools/GetMeTool.phpcreate mode 100644 database/migrations/2026_05_13_124153_create_mcp_feature_flag.phpcreate mode 100644 tests/Feature/Mcp/GetMeToolFeatureTest.phpcreate mode 100644 tests/Unit/Component/ES/ChunkSizeTest.phpcreate mode 100644 tests/Unit/Exceptions/RateLimitExceptionTest.phpcreate mode 100644 tests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.phplukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (master) $ git pullAlready up to date.lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (master) $ co -b JY-20676-delete-reSwitched to a new branch 'JY-20676-delete-report-related-objects'lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20676-delete-report-related-obHomeDMsActivityFilesLaterMore> 0EDJiminny ...# Jiminny-Dg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...• Direct messages€. Vasil Vasilev8. Nikolay Yankov%. Galya Dimitrova. Aneliya Angelovaão Stefka Stoyanova. Stoyan Tomovd Todor Stamatov "Kd. Mario GeorgievNikolay Ivanovd. James Graham2 Stoyan TanevRo Steliyan GeorgievLukas Kovalik y... OAppsJira CloudToastSupport Daily • in 3 h 27 m100% <78• Tue 19 May 11:33:37Describe what you are looking forNikolay Yankov6 0MessagesAdd canvasO Files+Nikolay YankovYesterday ~имаше ли нещь . y-..-Lukas Kovalik 2:28 PMтрябва да си вързан към SF да работиNikolay Yankov 2:28 PMaxaaaNikolay Yankov 2:41 PMимаме approve на PRда го даваме за QA?Lukas Kovalik 2:42 PMдаNikolay Yankov 3:02 PMтестове фейлватрьннах го 2 пътиToday ~Nikolay Yankov 10:05 AM/api/v2/user/ask-anything-prompts?target=on_demandhas_reports/api/v2/user/ask-anything-prompts/3381a35f-f1a3-431d-9510-bd079cd80ed6DELETE/api/vl/activity/saved-searchMessage Nikolay Yankov...
|
NULL
|
8409967248221515677
|
NULL
|
click
|
ocr
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpAPPDOCKER• ₴1D SlackFileEditViewGoHistoryWindowHelpAPPDOCKER• ₴1DEV (-zsh)₴82app/Jobs/Crm/MatchActivityCrmData.phpapp/Jobs/Middleware/HandleHubspotRateLimit.phpAPP (-zst47++++++p42++++++*app/Mcp/Servers/JiminnyServer.phpapp/Mcp/Tools/GetMeTool.php157++++++•app/Models/Feature/FeatureEnum.phpapp/Services/Activity/HubSpot/ProviderResolver.php+-app/Services/Activity/HubSpot/ProviderResolverInterface.phpapp/Services/Activity/HubSpot/Providers/Provider.phpapp/Services/Activity/HubSpot/Providers/ProviderKixie.php+-app/Services/Activity/HubSpot/Providers/Provider0rum.phpapp/Services/Activity/HubSpot/Providers/ProviderTwilio.phpapp/Services/Activity/HubSpot/Providers/ProviderTwilioFlex.phpapp/Services/Activity/HubSpot/Service.phpapp/Services/Crm/Hubspot/Client.phpapp/Services/Crm/Hubspot/HubspotClientInterface.phpapp/Services/Crm/Hubspot/Pagination/HubspotPaginationService.phpapp/Services/Crm/Hubspot/Pagination/PaginationState.phpdatabase/migrations/2026_05_13_124153_create_mcp_feature_flag.phptests/Feature/Mcp/GetMeToolFeatureTest.phptests/Feature/Mcp/ListCallsToolFeatureTest.phptests/Feature/Mcp/McpTestHelpersTrait.phptests/Unit/Component/ES/ChunkSizeTest.phptests/Unit/Component/ES/Processor/DT0s/SelectionListTest.phptests/Unit/Component/ES/Processor/TargetEntitiesSelectorTest.phptests/Unit/Component/MeetingBot/Service/ParticipantMatcherTest.phptests/Unit/Exceptions/RateLimitExceptionTest.phptests/Unit/Jobs/Crm/MatchActivityCrmDataTest.phptests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.phptests/Unit/Services/Activity/HubSpot/ServiceTest.phptests/Unit/Services/Crm/Hubspot/ClientTest.phptests/Unit/Services/Crm/Hubspot/Pagination/HubspotPaginationServiceTest.php97++++++-132++++++•15++++++21++++--2+-25++++++.140++++++•2+-19++++++50++++++-27++++++-39++++++-6856++++++-+-151++++++-109++++++-250++++++-283++++++=37 files changed, 1587 insertions(+), 344 deletions(-)create mode 100644 app/Component/ES/ChunkSize.phpcreate mode 100644 app/Jobs/Middleware/HandleHubspotRateLimit.phpcreate mode 100644 app/Mcp/Tools/GetMeTool.phpcreate mode 100644 database/migrations/2026_05_13_124153_create_mcp_feature_flag.phpcreate mode 100644 tests/Feature/Mcp/GetMeToolFeatureTest.phpcreate mode 100644 tests/Unit/Component/ES/ChunkSizeTest.phpcreate mode 100644 tests/Unit/Exceptions/RateLimitExceptionTest.phpcreate mode 100644 tests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.phplukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (master) $ git pullAlready up to date.lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (master) $ co -b JY-20676-delete-reSwitched to a new branch 'JY-20676-delete-report-related-objects'lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20676-delete-report-related-obHomeDMsActivityFilesLaterMore> 0EDJiminny ...# Jiminny-Dg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...• Direct messages€. Vasil Vasilev8. Nikolay Yankov%. Galya Dimitrova. Aneliya Angelovaão Stefka Stoyanova. Stoyan Tomovd Todor Stamatov "Kd. Mario GeorgievNikolay Ivanovd. James Graham2 Stoyan TanevRo Steliyan GeorgievLukas Kovalik y... OAppsJira CloudToastSupport Daily • in 3 h 27 m100% <78• Tue 19 May 11:33:37Describe what you are looking forNikolay Yankov6 0MessagesAdd canvasO Files+Nikolay YankovYesterday ~имаше ли нещь . y-..-Lukas Kovalik 2:28 PMтрябва да си вързан към SF да работиNikolay Yankov 2:28 PMaxaaaNikolay Yankov 2:41 PMимаме approve на PRда го даваме за QA?Lukas Kovalik 2:42 PMдаNikolay Yankov 3:02 PMтестове фейлватрьннах го 2 пътиToday ~Nikolay Yankov 10:05 AM/api/v2/user/ask-anything-prompts?target=on_demandhas_reports/api/v2/user/ask-anything-prompts/3381a35f-f1a3-431d-9510-bd079cd80ed6DELETE/api/vl/activity/saved-searchMessage Nikolay Yankov...
|
56840
|
NULL
|
NULL
|
NULL
|
|
56853
|
1979
|
1
|
2026-05-19T08:33:41.499883+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179621499_m2.jpg...
|
PhpStorm
|
faVsco.js – ActivityController.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
43
3
10
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Http\Controllers\API;
use Carbon\Carbon;
use ChaseConey\LaravelDatadogHelper\Datadog;
use Exception;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Rules\In;
use Illuminate\Validation\ValidationException;
use InvalidArgumentException;
use Jiminny\Component\ActivityAnalytics;
use Jiminny\Component\ActivitySearch;
use Jiminny\Component\ActivitySearch\FilterDefinitionCollection;
use Jiminny\Component\PlaybackPage\Comments\Services\ActivityCommentService;
use Jiminny\Component\Queue\Constants;
use Jiminny\Contracts\ES\Events\UpdateSingleEntity;
use Jiminny\Contracts\ES\UpdateTargetEnum;
use Jiminny\Contracts\Nudge\NudgeFactoryInterface;
use Jiminny\Contracts\Playlist\PlaylistTrackFactoryInterface;
use Jiminny\Contracts\Repositories\PlaylistActivityRepository;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Enums\TeamSetting;
use Jiminny\Events\Activities\AiAutomation\ActivityProspectAdded;
use Jiminny\Events\Activities\Coaching\Coached;
use Jiminny\Contracts\Services\Crm\SupportsObjectTypeParseInterface;
use Jiminny\Exceptions\LogicException;
use Jiminny\Exceptions\SocialAccountTokenInvalidException;
use Jiminny\Http\Controllers\API\BaseController as Controller;
use Jiminny\Http\Controllers\CommentContextInterface;
use Jiminny\Http\Responses\Api\AbstractResponse;
use Jiminny\Http\Responses\Api\Response;
use Jiminny\Http\Serializers\JsonSerializer;
use Jiminny\Http\Transformers\ActivityCommentTransformer;
use Jiminny\Http\Transformers\ActivityTopicTriggerTransformer;
use Jiminny\Http\Transformers\ActivityTransformer;
use Jiminny\Http\Transformers\AvailabilityNotificationTransformer;
use Jiminny\Http\Transformers\CoachingFeedbackTransformer;
use Jiminny\Http\Transformers\CoachingSectionsTransformer;
use Jiminny\Http\Transformers\SearchTransformer;
use Jiminny\Http\Transformers\StatsTransformer;
use Jiminny\Jobs\Crm\SaveActivity;
use Jiminny\Jobs\Crm\UpdateStage;
use Jiminny\Jobs\Telephony\StartRecording;
use Jiminny\Jobs\Telephony\StopRecording;
use Jiminny\Jobs\Telephony\ToggleRecording;
use Jiminny\Models\Account;
use Jiminny\Models\Activity;
use Jiminny\Models\Activity\CoachRequest;
use Jiminny\Models\Activity\Comment;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\Activity\Share;
use Jiminny\Models\CoachingFeedback;
use Jiminny\Models\CoachingSection;
use Jiminny\Models\CoachingSectionCriterion;
use Jiminny\Models\CoachingSectionFeedback;
use Jiminny\Models\Contact;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldData;
use Jiminny\Models\Crm\Layout;
use Jiminny\Models\Crm\LayoutEntity;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\LanguageDialect;
use Jiminny\Models\Lead;
use Jiminny\Models\Nudge;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Models\Playlist;
use Jiminny\Models\Stage;
use Jiminny\Models\Team;
use Jiminny\Models\Track;
use Jiminny\Models\User;
use Jiminny\Repositories\CoachingFeedbackRepository;
use Jiminny\Repositories\ElasticActivityRepository;
use Jiminny\Repositories\TeamRepository;
use Jiminny\Rules\CrmReference;
use Jiminny\Rules\MultidimensionalArrayMaxCharRule;
use Jiminny\Services\ActivityService;
use Jiminny\Services\Crm\ProviderRegistry;
use Jiminny\Services\PlaybackService;
use Jiminny\Services\UserService;
use Jiminny\VO\Repository\OnDemandActivitySearch\Criteria;
use Psr\Log\LoggerInterface;
use Ramsey\Uuid\Uuid;
use Sentry;
use Symfony\Component\HttpFoundation;
final class ActivityController extends Controller implements CommentContextInterface
{
// Number of minutes to look back on activities. i.e. a timeout on activity duration.
private const int LOOK_BACK = 180;
public function __construct(
private ProviderRegistry $providerRegistry,
private ActivityService $activityService,
Response $response,
private UserService $userService,
private ActivitySearch\Service\ActivitySearch $activitySearch,
private NudgeFactoryInterface $nudgeFactory,
private ActivityCommentService $activityCommentService,
private LoggerInterface $logger,
private readonly CoachingFeedbackRepository $coachingFeedbackRepository,
private readonly TeamRepository $teamRepository,
) {
parent::__construct($response);
}
public static function getCommentImplementation(): string
{
return Comment::class;
}
public function delete()
{
$this->request->validate([
'*' => 'uuid:activities',
]);
$deletedIds = [];
foreach ($this->request->all() as $activityId) {
$activity = Activity::idOrUuId($activityId);
try {
if ($this->authorize('delete', $activity)) {
$activity->delete();
$deletedIds[] = $activityId;
\Log::info('Soft deleted activity ' . $activity->id_string . ' by user ' . $this->getUser()->id);
}
} catch (AuthorizationException $authorizationException) {
// They didn't have permission.
}
}
return $this->response->withArray($deletedIds);
}
public function update(Request $request, Activity $activity)
{
$this->authorize('updateMetadata', $activity);
$request->validate([
'title' => 'string|max:250',
'category_id' => 'uuid:playbook_categories',
'language' => [
new In(
LanguageDialect::query()
->with('language')
->cursor()
->map(static function (LanguageDialect $languageDialect): string {
return $languageDialect->getLanguageLocale();
})
->all()
),
],
]);
if ($request->has('title')) {
$activity->title = $request->input('title');
}
if ($request->has('category_id')) {
$category = PlaybookCategory::uuid($request->input('category_id'));
if ($category->playbook->team_id !== $request->user()->team_id) {
return $this->response->errorNotFound('Sorry, this category does not belong to your playbook.');
}
$activity->playbook_category_id = $category->id;
}
if ($request->has('language')) {
if (! $activity->isInProgress()) {
return $this->response->withError(
'Activity language can only be set while the meeting is in progress.',
400
);
}
$activity->setLanguageCode($request->input('language'));
}
$activity->save();
return $this->response->withOk();
}
// XXX: This should be merged with the update method.
/**
* @param Activity $activity
*
* @throws AuthorizationException
* @throws SocialAccountTokenInvalidException
*
* @return mixed
*/
public function summarize(Activity $activity): mixed
{
$this->logger->info('[Log Activity] Summarizing activity ', [
'activityId' => $activity->getUuid(),
'payload' => $this->request->all(),
]);
$this->authorize('update', $activity);
$this->logger->info('[Log Activity] Validating summary');
// Validate the payload.
$this->validateSummary($activity);
// All objects must belong to this team.
/** @var User $user */
$user = $this->request->user();
$team = $user->getTeam();
$crmService = $this->providerRegistry->get($team->crm->provider);
try {
$crmUser = $user;
if ($user->isCrmRequired() === false) {
$crmUser = $team->owner;
}
$crmService->setUser($crmUser);
} catch (SocialAccountTokenInvalidException $accountTokenInvalidException) {
// Return a JSON response with the response array and status code.
return $this->response->errorWrongArgs($accountTokenInvalidException->getMessage());
}
$rawEntities = $this->request->input('entities');
/** @var Layout $layout */
$layout = $team->crm->layouts()->uuid(
$this->request->input('layout_id')
);
// Delay execution of CRM jobs to avoid locking issues.
$jobDelay = 0;
// If we have arrived from a notification, mark it as read.
$notificationId = $this->request->input('nId');
if ($notificationId) {
$notification = $user->unreadNotifications->where('id', $notificationId)->first();
if ($notification) {
$notification->markAsRead();
}
}
$title = $this->request->input('title');
$prospects = $this->request->input('prospects');
$opportunityId = $this->request->input('opportunity_id');
$stageId = $this->request->input('stage_id');
$categoryId = $this->request->input('category_id');
$summary = $this->request->input('summary');
$crmProviderId = $this->request->input('crm_id');
$isInternal = $this->request->input('is_internal') ?? false;
$lead = null;
$category = null;
$account = null;
$contact = null;
$opportunity = null;
$stage = null;
$callStage = null;
foreach ($prospects as $prospectData) {
$objectId = $prospectData['id'];
if ($objectId === null) {
continue;
}
$objectType = $prospectData['type'];
$this->logger->info('debug', ['prospect_data' => $prospectData]);
try {
if ($objectType === null) {
$this->logger->info('no object type');
if ($crmService instanceof SupportsObjectTypeParseInterface) {
$objectType = $crmService->parseObjectType($objectId);
}
}
switch ($objectType) {
case 'lead':
$this->logger->info('Processing lead');
/** @var Lead|null $lead */
$lead = $team->crm->leads()->where('crm_provider_id', $objectId)->first();
// Lead does not exist locally, import it.
if ($lead === null) {
$this->logger->info('Lead does not exist locally');
/** @var Lead $lead */
$lead = $crmService->syncLead($objectId);
}
$this->logger->info('Lead found', ['leadId' => $lead->id]);
$activity->lead_id = $lead->id;
if ($stageId === null) {
$this->logger->info('Stage ID is null');
// If it was not provided, just assume it is the current stage.
$callStage = $lead->stage;
break;
}
$this->logger->info('Looking for stage');
// Determine if they have changed the stage.
/** @var Stage $stage */
$stage = $team->crm->stages()
->uuid($stageId, false)
->where('type', Stage::TYPE_LEAD)
->firstOrFail();
$this->logger->info('Stage found', ['stageId' => $stage->id, 'lead_stage' => $lead->stage_id]);
if ($lead->stage_id && $lead->stage_id !== $stage->id) {
$this->logger->info('Stage has changed');
// Storage current stage on activity.
$callStage = $lead->stage;
// The stage has changed, update in remote CRM.
dispatch(new UpdateStage($activity, $lead, $callStage, $stage));
$this->logger->info(
sprintf(
'[%s] User changing lead stage from %s to %s',
$crmService->getDisplayName(),
$callStage->getName(),
$stage->getName()
),
[
'user' => $user->getUuid(),
'lead' => $lead->getUuid(),
]
);
} else {
$this->logger->info('Stage has not changed');
// Stage remains as current.
$callStage = $stage;
}
break;
case 'account':
$this->logger->info('Processing account');
// If the object is not a lead, it should be an account.
$account = $team->crm->accounts()->where('crm_provider_id', $objectId)->first();
// Account does not exist locally, import it.
if ($account === null) {
$this->logger->info('Account does not exist locally');
$account = $crmService->syncAccount($objectId);
}
$this->logger->info('Account found', ['accountId' => $account->id]);
break;
case 'contact':
$this->logger->info('processing contact');
$contact = $team->crm->contacts()->where('crm_provider_id', $objectId)->first();
// Contact does not exist locally, import it.
if (! $contact instanceof Contact) {
$this->logger->info('contact does not exist locally');
$contact = $crmService->syncContact($objectId);
}
$this->logger->info('resolving account');
$account = $this->resolveAccount($team, $contact, $crmService, $prospects);
break;
}
// If they have specified an opportunity, retrieve this with stage.
if ($opportunityId) {
$this->logger->info('opportunity id is set');
$opportunity = $team->crm->opportunities()->where('crm_provider_id', $opportunityId)->first();
// Opportunity does not exist locally, import it.
if ($opportunity === null) {
$this->logger->info('opportunity does not exist locally');
$opportunity = $crmService->syncOpportunity($opportunityId);
}
if ($stageId === null) {
$this->logger->info('stage id is null');
// If it was not provided, just assume it is the current stage.
$callStage = $opportunity->stage ?? null;
} else {
$this->logger->info('looking for stage');
/** @var ?Stage $opportunityStage */
$opportunityStage = $team->crm
->stages()
->uuid($stageId, false)
->where('type', Stage::TYPE_OPPORTUNITY)
->first();
// There is a chance we still cannot import this opportunity.
if ($opportunityStage !== null && $opportunity !== null && $opportunity->stage_id !== $opportunityStage->id) {
$this->logger->info('opportunity stage has changed');
// Storage current stage on activity.
$callStage = $opportunity->stage;
dispatch(new UpdateStage($activity, $opportunity, $callStage, $opportunityStage));
$this->logger->info(
sprintf(
'[%s] User changing opportunity stage from %s to %s',
$crmService->getDisplayName(),
$callStage->name,
$opportunityStage->name
),
[
'userId' => $user->id_string,
'opportunityId' => $opportunity->id_string,
]
);
} else {
$this->logger->info('opportunity stage has not changed');
// Stage remains as current.
$callStage = $opportunityStage;
}
}
}
if ($crmProviderId) {
// Cast $crmProviderId to string otherwise it won't use database index for some records
$linkedActivity = Activity::where('crm_provider_id', (string) $crmProviderId)->first();
// Check if this activity has already been assigned to a different activity.
if ($linkedActivity && $linkedActivity->id !== $activity->id) {
throw new InvalidArgumentException(
'Sorry, the linked task has already been logged under a different call. '
. 'Please choose another linked task.'
);
}
}
} catch (InvalidArgumentException $exception) {
$this->logger->error('Failed to process prospect', [
'prospect_data' => $prospectData,
'reason' => $exception->getMessage(),
]);
// Return a JSON response with the response array and status code.
return $this->response->errorWrongArgs($exception->getMessage());
} catch (Exception $exception) {
$this->logger->error('Failed to process prospect', [
'prospect_data' => $prospectData,
'reason' => $exception->getMessage(),
]);
// Return a JSON response with the response array and status code.
return $this->response->errorInternalError(
'Sorry, an error occurred. Please try again or reach out to support if the problem continues.'
);
}
}
if ($categoryId) {
$category = PlaybookCategory::uuid($categoryId);
if ($category->playbook->team_id !== $team->id) {
throw new InvalidArgumentException('Sorry, this category does not belong to your playbook.');
}
$activity->playbook_category_id = $category->id;
}
$this->logger->info('Prospect data', [
'lead_id' => $lead?->getId(),
'account_id' => $account?->getId(),
'contact_id' => $contact?->getId(),
'opportunity_id' => $opportunity?->getId(),
'stage_id' => $stage?->getId(),
]);
if ($title) {
$activity->title = $title;
}
if ($summary) {
$activity->summary = $summary;
}
if ($crmProviderId) {
$activity->crm_provider_id = $crmProviderId;
}
if ($callStage) {
$this->logger->info('Setting stage id', ['stageId' => $callStage->id]);
$activity->stage_id = $callStage->id;
}
if ($lead) {
$this->logger->info('Setting lead id', ['leadId' => $lead->id]);
$activity->lead_id = $lead->id;
// If we are changed from an account > lead, unset the account data.
$this->logger->info('Unsetting account id, opportunity id, contact id, value');
$activity->account_id = null;
$activity->opportunity_id = null;
$activity->contact_id = null;
$activity->value = null;
}
if ($account) {
$this->logger->info('Setting account id', ['accountId' => $account->id]);
$activity->account_id = $account->id;
// If we are changed from an lead > account, unset the lead data.
$this->logger->info('unsetting lead id');
$activity->lead_id = null;
// Unset the contact if switching different accounts. Will be set up below if still applicable.
if (! $team->hasFeature(FeatureEnum::LINK_ACTIVITY_TO_MULTIPLE_PROSPECTS) || empty($contact)) {
$this->logger->info('Unsetting contact id');
$activity->contact_id = null;
}
}
if ($opportunity) {
$this->logger->info('setting opportunity id', ['opportunityId' => $opportunity->id]);
$this->logger->info('unsetting lead id');
$activity->opportunity_id = $opportunity->id;
$activity->value = $opportunity->value;
// If we are changed from an lead > account, unset the lead data.
$activity->lead_id = null;
}
if ($contact) {
$this->logger->info('setting contact id', ['contactId' => $contact->id]);
$activity->contact_id = $contact->id;
// If we are changed from an lead > account, unset the lead data.
$this->logger->info('Unsetting lead id');
$activity->lead_id = null;
}
$activity->is_internal = $isInternal;
$activity->save();
$activity->refresh();
$this->logger->notice('Activity saved', [
'activity_id' => $activity->getId(),
'lead_id' => $activity->lead_id,
'account_id' => $activity->account_id,
'contact_id' => $activity->contact_id,
'opportunity_id' => $activity->opportunity_id,
'stage_id' => $activity->stage_id,
'crm_provider_id' => $activity->getCrmProviderId(),
]);
// Store entities as field data on the activity.
$updatedData = $this->storeEntities($crmService, $activity, $layout, $rawEntities);
if ($activity->isLoggable()) {
// Follow-up Task or Event data.
$followupData = $this->fetchFollowupEntities($crmService, $layout, $rawEntities);
$this->logger->info('CRM LOG manual log triggered', [
'activityId' => $activity->getUuid(),
'followupData' => $followupData,
'userId' => $user->getUuid(),
]);
// Store data in the CRM.
// ++add check for crm_required
$job = new SaveActivity($activity, $followupData);
if ($updatedData) {
$job->delay(Carbon::now()->addMinutes($jobDelay));
}
dispatch($job);
// Manually dispatch log for Opportunity or Prospect added
if ($activity->hasOpportunity() || $activity->hasProspect()) {
event(new ActivityProspectAdded(
activity: $activity,
eventSource: 'manually-log-crm-data'
));
}
}
return $this->response->withOk();
}
/**
* Extract any activity data to be upserted in the Lead/Opportunity/Task etc in the CRM.
*
* @param ServiceInterface $service
* @param Activity $activity
* @param Layout $layout
* @param array $entities The raw entity data from user
*
* @return array
*/
private function storeEntities(ServiceInterface $service, Activity $activity, Layout $layout, array $entities): array
{
$updatedData = [];
$existingData = $activity->data()->get();
// We need to delete any existing data to overwrite with latest values.
$activity->data()->delete();
$layoutEntities = $layout->entities()
->with('field', 'parent')
->whereHas('field', function ($query) {
$query->where('is_selectable', 1);
})
->get();
/** @var LayoutEntity $entity */
foreach ($layoutEntities as $entity) {
// If the user has provided a value for this entity
if (array_key_exists($entity->id_string, $entities)) {
$value = $entities[$entity->id_string];
// Convert raw data into values that the CRM can consume.
if ($value) {
$value = $service->normalizeValue($entity->field->type, $value);
}
// Check the field is part of the activity-summary section.
if ($entity->parent && $entity->parent->label === 'activity-summary' && $value) {
// This is the internal database ID, not the external CRM ID.
$objectId = null;
switch ($entity->field->object_type) {
case Field::OBJECT_ACCOUNT:
$objectId = $activity->account_id;
break;
case Field::OBJECT_CONTACT:
$objectId = $activity->contact_id;
break;
case Field::OBJECT_OPPORTUNITY:
$objectId = $activity->opportunity_id;
break;
case Field::OBJECT_LEAD:
$objectId = $activity->lead_id;
break;
case Field::OBJECT_TASK:
case Field::OBJECT_EVENT:
$objectId = $activity->id;
break;
}
if ($objectId) {
/** @var FieldData $data */
$data = $activity->data()->create([
'crm_layout_entity_id' => $entity->id,
'crm_field_id' => $entity->crm_field_id,
'object_type' => $entity->field->object_type,
'object_id' => $objectId,
'value' => $value,
]);
// Never send read-only field data to the CRM.
if ($entity->read_only === false && $entity->is_visible) {
$existingValue = $existingData
->where('crm_layout_entity_id', $entity->id)
->where('crm_field_id', $entity->crm_field_id)
->where('object_type', $entity->field->object_type)
->where('object_id', $objectId)
->first();
// If the field was actually changed, we need to reflect this in the CRM too.
if ($existingValue === null || $existingValue->value !== $value) {
$updatedData[] = $data->id;
}
}
}
}
}
}
return $updatedData;
}
/**
* Extract any followup data to be dispatched in a job to create a new Task/Event in the CRM.
*
* @param ServiceInterface $crmService
* @param Layout $layout
* @param array $entities The raw entity data from user
*
* @return array
*/
private function fetchFollowupEntities(ServiceInterface $crmService, Layout $layout, array $entities): array
{
$fieldData = [];
foreach ($entities as $entityId => $value) {
// Only bother with fields that have a value.
if ($value) {
// Extract the entity from the UUID. Check the field is valid and part of the follow-up section.
$entity = $layout->entities()
->uuid($entityId, false)
->whereHas('parent', function ($query) {
$query->where('label', 'follow-up');
})
->whereHas('field', function ($query) {
$query->where('is_selectable', 1);
})
->first();
if ($entity) {
// Convert raw data into values that the CRM can consume.
$value = $crmService->normalizeValue($entity->field->type, $value);
// Add the field and value to the payload.
$fieldData += [
$entity->field->crm_provider_id => $value,
];
}
}
}
return $fieldData;
}
/**
* @param Activity $activity
*/
private function validateSummary(Activity $activity): void
{
$team = $activity->user->team;
$crmProvider = $team->crm->provider;
$attributes = [];
$rules = [
'layout_id' => 'required|uuid:crm_layouts,crm_configuration_id,' . $team->crm_id,
'title' => 'string|max:250',
'prospects' => 'required|array',
'opportunity_id' => new CrmReference($crmProvider),
'category_id' => 'uuid:playbook_categories|required_unless:is_internal,true',
'stage_id' => 'uuid:stages,team_id,' . $team->id, // Todo: move to proper validator
'summary' => 'max:50000',
'nId' => 'exists:notifications,id',
'crm_id' => new CrmReference($crmProvider),
'entities' => 'array',
'is_internal' => 'boolean',
];
/** @var Layout $layout */
$layout = $team->crm->layouts()->uuid($this->request->input('layout_id'));
// Only validate fields, not headers etc. If not loggable, we don't care about follow-up section.
$entities = $layout->entities()
->where('read_only', 0)
->whereHas('field', function ($query) {
$query->where('is_selectable', 1);
})
->whereHas('parent', function ($query) use ($activity) {
if ($activity->isLoggable() === false) {
$query->where('label', '<>', 'follow-up');
}
});
$isInternal = $this->request->input('is_internal', false);
foreach ($entities->get() as $entity) {
$rules += $this->buildFieldValidator($entity, $isInternal);
$attributes += $this->buildFieldMessage($entity);
}
$this->request->validate($rules, [], $attributes);
}
private function buildFieldValidator(LayoutEntity $entity, bool $isInternal): array
{
return [
'entities.' . $entity->id_string => $entity->getValidator($isInternal),
];
}
/**
* @param LayoutEntity $entity
*
* @return array
*/
private function buildFieldMessage(LayoutEntity $entity): array
{
$label = $entity->label;
if ($label === null) {
$label = $entity->field->label;
}
return [
'entities.' . $entity->id_string => $label,
];
}
public function search(Request $request, ElasticActivityRepository $repository): JsonResponse
{
/** @var User $user */
$user = $request->user();
$this->debugLog(
$user,
'User extracted from request',
['user' => $user->getId(), 'tz' => $user->getTimezone()]
);
$searchCriteria = Criteria::createFromRequest($request->all(), $user->getTimezone());
$this->debugLog(
$user,
'ActivitySearch criteria built',
['searchCriteria' => $searchCriteria]
);
$filterSet = $this->activitySearch->getHomepageFilterSet($searchCriteria, $user);
$this->debugLog($user, 'FilterSet built', ['filterSet' => $filterSet]);
$this->validateSearch($request, $filterSet);
$this->debugLog($user, 'Request validated');
$searchResponse = $repository->onDemandSearch($user, $searchCriteria, $filterSet);
/** @var Collection<Activity> $activities */
$activities = $searchResponse['results'];
$this->debugLog($user, 'Activities ES response extracted');
$hideInternalMeetingsSetting = $this->teamRepository->getTeamSettingByTeamId(
$user->getTeamId(),
TeamSetting::HIDE_INTERNAL_SCHEDULED_MEETINGS->name(),
);
if ($hideInternalMeetingsSetting?->getValue() === '1') {
$activities = $activities->filter(function (Activity $activity) {
if ($activity->is_internal && empty($activity->actual_start_time)) {
return false;
}
return true;
});
}
$this->debugLog($user, 'Internal meetings (?!) filtered');
$this->response->getManager()
->parseIncludes([
'category',
'organizer.group',
'prospect',
'stage',
'opportunity',
'stats',
'scorecards',
'masterTrack',
'activeParticipants',
'notification',
])
->setSerializer(new JsonSerializer());
$transformerExcludes = $this->request->input('exclude');
if ($transformerExcludes) {
$this->response->getManager()->parseExcludes($transformerExcludes);
}
$this->debugLog($user, 'Response Manager (?!) applied');
$transformer = new ActivityTransformer();
$transformer->setConsumer($user);
$this->debugLog($user, 'Activity Transformer added');
$resource = new \League\Fractal\Resource\Collection($activities, $transformer);
$page = $searchCriteria->getPageNumber();
$this->debugLog($user, 'Search criteria page number called', ['page' => $page]);
$histogram = array_pluck(array_get($searchResponse, 'histogram.buckets', []), 'doc_count', 'key_as_string');
$this->debugLog($user, 'Histogram generated. Response is ready.', ['histogram' => $histogram]);
return $this->response->withArray([
'pagination' => [
'total' => $searchResponse['totalHits'],
'current' => $page,
'prev' => max($page - 1, 1),
'next' => $page + 1,
],
'results' => $this->response->getManager()->createData($resource)->toArray(),
'histogram' => $histogram,
]);
}
private function debugLog(User $user, string $logMessage, ?array $context = []): void
{
// Debug for Learning People Only
if ($user->getTeamId() !== 260) {
return;
}
Log::notice(
sprintf('[activity-search-controller] %s', $logMessage),
$context
);
}
/** @throws ValidationException */
private function validateSearch(Request $request, FilterDefinitionCollection $filterSet, ?string $prefix = null): void
{
$rules = [
'exclude' => 'array',
'limit' => 'integer|min:1|max:50',
'page' => 'integer|min:1',
];
if ($prefix !== null && mb_strpos($prefix, '.') !== false) {
$rules[rtrim($prefix, '.')] = sprintf(
'required|array|max:%d',
$filterSet->count()
);
}
$validationRules = $filterSet->getValidationRules($prefix)
->merge($rules)
->all();
$request->validate($validationRules);
}
public function createActivitySearch(Request $request, SearchTransformer $searchTransformer): JsonResponse
{
/** @var User $user */
$user = $request->user();
$search = $this->updateOrCreateActivitySearch($request);
$this->response
->getManager()
->setSerializer(new JsonSerializer());
return $this->response->withItem(
$search,
$searchTransformer
->withConsumer($user)
);
}
public function updateActivitySearch(Request $request, Search $search): JsonResponse
{
$this->authorize('update', $search);
$this->updateOrCreateActivitySearch($request, $search);
return $this->response->withOk();
}
private function storeNamedSearchFilters(
Collection $request,
Search $search,
FilterDefinitionCollection $filterSet,
?string $prefix = null,
): self {
$arrayTypeProperties = $filterSet
->getPropertyTypes([
FilterDefinitionCollection::PROPERTY_TYPE_ARRAY,
])
->all();
$supportedRequestProperties = $filterSet->getSupportedRequestProperties($prefix);
foreach ($supportedRequestProperties as $requestPropertyName) {
if (! array_has($request, $requestPropertyName)) {
continue;
}
/** @var string|string[] $propertyValue */
$propertyValue = array_get($request, $requestPropertyName);
$propertyName = $prefix === null
? $requestPropertyName
: mb_substr($requestPropertyName, mb_strlen($prefix));
$isArrayType = array_has($arrayTypeProperties, $propertyName);
if (! $isArrayType) {
/** @var string $requestPropertyValue */
$search->filters()->updateOrCreate(
[
'filter' => $propertyName,
],
[
'value' => $propertyValue,
]
);
continue;
}
/** @var string[] $requestPropertyValue */
/** @var SearchFilter[]|Collection $existingFilterValues */
$existingFilterValuesKeyed = $search->filters()
->where('filter', $propertyName)
->get()
->keyBy('id');
// Iterate over values provided as request parameters
foreach ($propertyValue as $value) {
/** @var SearchFilter|null $valueFilter */
$valueFilter = $search->filters()
->where(
[
'filter' => $propertyName,
'value' => $value,
]
)
->first();
if ($valueFilter !== null) {
// Remove filter value pair from list to be deleted
$existingFilterValuesKeyed->forget($valueFilter->id);
} else {
// Add new filter/value pair
$search->filters()->updateOrCreate([
'filter' => $propertyName,
'value' => $value,
]);
}
}
// Delete filter value pairs for this filter that no longer exist in request parameters
foreach ($existingFilterValuesKeyed as $existingFilter) {
$existingFilter->delete();
}
}
/** @var Collection<int, SearchFilter> $filtersKeyed */
$filtersKeyed = $search->filters()->get()->keyBy('filter');
// wipe removed filters from this search
foreach ($filtersKeyed as $filterName => $filter) {
if (array_has($request, $prefix . $filterName)) {
continue;
}
// Remove all filter values for this filter
$search->filters()->where('filter', $filterName)->delete();
}
return $this;
}
/**
* @throws AuthorizationException
*/
public function fetchActivitySearch(
Search $search,
Request $request,
SearchTransformer $searchTransformer,
): JsonResponse {
$this->authorize('view', $search);
/** @var User $user */
$user = $request->user();
$this->response
->getManager()
->setSerializer(new JsonSerializer());
return $this->response->withItem(
$search,
$searchTransformer
->withConsumer($user)
);
}
public function listActivitySearch(Request $request, SearchTransformer $searchTransformer): JsonResponse
{
/** @var User $user */
$user = $request->user();
$this->response
->getManager()
->setSerializer(new JsonSerializer());
return $this->response->withCollection(
$user->searches()->get(),
$searchTransformer
->withConsumer($user)
);
}
/**
* Deletes a saved search
*
* @param Request $request
* @param Search $search
*
* @throws Exception
*
* @return JsonResponse
*/
public function deleteActivitySearch(Request $request, Search $search): JsonResponse
{
$this->authorize('delete', $search);
// Disable and orphan any AutomatedReports that use this search
$search->automatedReports()->withTrashed()->update([
'activity_search_id' => null,
'status' => false,
]);
// Delete filters and the search itself
$search->filters()->delete();
$search->delete();
return $this->response->withOk();
}
public function live(Request $request, ElasticActivityRepository $repository): JsonResponse
{
$user = $this->getUserFromRequest($request);
$this->request->validate([
'sort_direction' => 'in:asc,desc',
'limit' => 'integer|min:1|max:50',
'page' => 'integer|min:1',
]);
$activities = $repository->getLiveCoachingEligibleActivities(
user: $user,
lookBackMinutes: self::LOOK_BACK,
limit: (int) $this->request->input('limit', 25),
page: (int) $this->request->input('page', 1),
sortBy: ['actual_start_time', 'scheduled_start_time'],
sortDirection: (string) $this->request->input('sort_direction', 'asc'),
);
$this->response
->getManager()
->parseIncludes(['organizer.group', 'prospect'])
->setSerializer(new JsonSerializer());
return $this->response->withCollection($activities, new ActivityTransformer());
}
/**
* @param Activity $activity
*
* @throws AuthorizationException
*
* @return mixed
*/
public function show(Activity $activity, ActivityService $activityService): JsonResponse
{
$this->authorize('show', $activity);
$user = $activity->getUser();
$team = $user->getTeam();
// Sync the opportunity with the latest data if possible.
if ($activity->opportunity_id) {
try {
$crmService = $this->providerRegistry->get($team->crm->provider);
if (! $user->isCrmRequired()) {
$crmService->setUser($team->getOwner());
} else {
$crmService->setUser($user);
}
$crmService->syncOpportunity($activity->opportunity->crm_provider_id);
} catch (Exception $exception) {
// Move on.
}
}
$activityData = $activityService->getActivityData($this->request->user(), $activity);
return response()->json($activityData);
}
public function createRecording(Activity $activity)
{
$this->authorize('record', $activity);
if ($activity->hasRecordingReasonComplianceRestricted()) {
return $this->response->errorGone('Recording this number has been disabled by your organization.');
}
// Tell Twilio to start recording this activity.
if ($activity->recording_state === Activity::RECORDING_OFF) {
$job = (new StartRecording($activity))->onQueue(Constants::QUEUE_CONFERENCES);
dispatch($job);
return $this->response->withCreated();
}
return $this->response->errorGone('Activity is already recording.');
}
public function updateRecording(Request $request, Activity $activity)
{
$this->authorize('record', $activity);
$request->validate([
'preference' => 'boolean',
'state' => [
'string',
Rule::in([
Activity::RECORDING_IN_PROGRESS,
Activity::RECORDING_PAUSED,
]),
],
]);
if ($request->has('state')) {
if ($activity->hasRecordingReasonComplianceRestricted()) {
return $this->response->errorGone('Recording this number has been disabled by your organization.');
}
// Toggle the recording state between paused and resumed.
if (! $activity->isRecordingState(Activity::RECORDING_OFF)) {
$job = (new ToggleRecording($activity, $request->input('state')))
->onQueue(Constants::QUEUE_CONFERENCES);
dispatch($job);
return $this->response->withOk();
}
return $this->response->errorGone('Recording is not toggleable.');
}
if ($request->has('preference')) {
$activity->update([
'recording_preference' => $request->input('preference') ? 1 : 0,
]);
return $this->response->withOk();
}
return $this->response->errorWrongArgs('Something went wrong');
}
public function stopRecording(Activity $activity)
{
$this->authorize('stopRecord', $activity);
// Tell Twilio to stop recording this activity.
if ($activity->isRecordingState(Activity::RECORDING_IN_PROGRESS)) {
$job = (new StopRecording($activity))->onQueue(Constants::QUEUE_CONFERENCES);
dispatch($job);
return $this->response->withOk();
}
return $this->response->errorGone('Activity is not recording.');
}
/**
* Add activity to this user's favorites playlist
*
* @throws AuthorizationException
*/
public function favorite(Activity $activity, PlaylistActivityRepository $playlistActivityRepository): JsonResponse
{
$this->authorize('favorite', $activity);
$user = $this->getUserFromRequest($this->request);
$favorite = $activity->wasFavoritedBy($user);
$name = $activity->activity_title ?? '';
// It needs to check at least one record.
if (! $favorite) {
$favoritePlaylist = $user->favoritePlaylist();
$playlistActivity = $playlistActivityRepository->findByBaseActivityUserAndPlaylist(
$activity,
$user,
$favoritePlaylist
);
if ($playlistActivity !== null) {
$playlistActivity->update(
// Just update, don't sort.
['start_time' => 0, 'name' => mb_strimwidth($name, 0, 100)],
);
} else {
$playlistActivity = $activity->playlistActivities()->create([
'playlist_id' => $favoritePlaylist->getId(),
'user_id' => $user->getId(),
'start_time' => 0,
'name' => mb_strimwidth($name, 0, 100),
]);
// Sort it on top.
$playlistActivity->update(
[
'sort' => $playlistActivityRepository->calculateNewSortOrder(
null,
$playlistActivity,
),
],
);
}
$playlistActivityRepository->calculateNewSortOrder(null, $playlistActivity);
return new JsonResponse([], JsonResponse::HTTP_CREATED);
}
return new JsonResponse(
[
'error' => [
'code' => AbstractResponse::CODE_CONFLICT,
'http_code' => JsonResponse::HTTP_CONFLICT,
'message' => 'Resource Already Exists',
],
],
JsonResponse::HTTP_CONFLICT,
);
}
/**
* Remove activity from this user's favorites playlist
*
* @param Activity $activity
*
* @throws AuthorizationException
*
* @r...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.098071806,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"43","depth":4,"bounds":{"left":0.36901596,"top":0.15003991,"width":0.010305851,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"3","depth":4,"bounds":{"left":0.38131648,"top":0.15003991,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"10","depth":4,"bounds":{"left":0.3912899,"top":0.15003991,"width":0.009640957,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.40292552,"top":0.15003991,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.4119016,"top":0.14844373,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.4192154,"top":0.14844373,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Http\\Controllers\\API;\n\nuse Carbon\\Carbon;\nuse ChaseConey\\LaravelDatadogHelper\\Datadog;\nuse Exception;\nuse Illuminate\\Auth\\Access\\AuthorizationException;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Http\\JsonResponse;\nuse Illuminate\\Http\\Request;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Validation\\Rule;\nuse Illuminate\\Validation\\Rules\\In;\nuse Illuminate\\Validation\\ValidationException;\nuse InvalidArgumentException;\nuse Jiminny\\Component\\ActivityAnalytics;\nuse Jiminny\\Component\\ActivitySearch;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionCollection;\nuse Jiminny\\Component\\PlaybackPage\\Comments\\Services\\ActivityCommentService;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Contracts\\ES\\Events\\UpdateSingleEntity;\nuse Jiminny\\Contracts\\ES\\UpdateTargetEnum;\nuse Jiminny\\Contracts\\Nudge\\NudgeFactoryInterface;\nuse Jiminny\\Contracts\\Playlist\\PlaylistTrackFactoryInterface;\nuse Jiminny\\Contracts\\Repositories\\PlaylistActivityRepository;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Enums\\TeamSetting;\nuse Jiminny\\Events\\Activities\\AiAutomation\\ActivityProspectAdded;\nuse Jiminny\\Events\\Activities\\Coaching\\Coached;\nuse Jiminny\\Contracts\\Services\\Crm\\SupportsObjectTypeParseInterface;\nuse Jiminny\\Exceptions\\LogicException;\nuse Jiminny\\Exceptions\\SocialAccountTokenInvalidException;\nuse Jiminny\\Http\\Controllers\\API\\BaseController as Controller;\nuse Jiminny\\Http\\Controllers\\CommentContextInterface;\nuse Jiminny\\Http\\Responses\\Api\\AbstractResponse;\nuse Jiminny\\Http\\Responses\\Api\\Response;\nuse Jiminny\\Http\\Serializers\\JsonSerializer;\nuse Jiminny\\Http\\Transformers\\ActivityCommentTransformer;\nuse Jiminny\\Http\\Transformers\\ActivityTopicTriggerTransformer;\nuse Jiminny\\Http\\Transformers\\ActivityTransformer;\nuse Jiminny\\Http\\Transformers\\AvailabilityNotificationTransformer;\nuse Jiminny\\Http\\Transformers\\CoachingFeedbackTransformer;\nuse Jiminny\\Http\\Transformers\\CoachingSectionsTransformer;\nuse Jiminny\\Http\\Transformers\\SearchTransformer;\nuse Jiminny\\Http\\Transformers\\StatsTransformer;\nuse Jiminny\\Jobs\\Crm\\SaveActivity;\nuse Jiminny\\Jobs\\Crm\\UpdateStage;\nuse Jiminny\\Jobs\\Telephony\\StartRecording;\nuse Jiminny\\Jobs\\Telephony\\StopRecording;\nuse Jiminny\\Jobs\\Telephony\\ToggleRecording;\nuse Jiminny\\Models\\Account;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Activity\\CoachRequest;\nuse Jiminny\\Models\\Activity\\Comment;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\Activity\\Share;\nuse Jiminny\\Models\\CoachingFeedback;\nuse Jiminny\\Models\\CoachingSection;\nuse Jiminny\\Models\\CoachingSectionCriterion;\nuse Jiminny\\Models\\CoachingSectionFeedback;\nuse Jiminny\\Models\\Contact;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldData;\nuse Jiminny\\Models\\Crm\\Layout;\nuse Jiminny\\Models\\Crm\\LayoutEntity;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\LanguageDialect;\nuse Jiminny\\Models\\Lead;\nuse Jiminny\\Models\\Nudge;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Models\\Playlist;\nuse Jiminny\\Models\\Stage;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\Track;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\CoachingFeedbackRepository;\nuse Jiminny\\Repositories\\ElasticActivityRepository;\nuse Jiminny\\Repositories\\TeamRepository;\nuse Jiminny\\Rules\\CrmReference;\nuse Jiminny\\Rules\\MultidimensionalArrayMaxCharRule;\nuse Jiminny\\Services\\ActivityService;\nuse Jiminny\\Services\\Crm\\ProviderRegistry;\nuse Jiminny\\Services\\PlaybackService;\nuse Jiminny\\Services\\UserService;\nuse Jiminny\\VO\\Repository\\OnDemandActivitySearch\\Criteria;\nuse Psr\\Log\\LoggerInterface;\nuse Ramsey\\Uuid\\Uuid;\nuse Sentry;\nuse Symfony\\Component\\HttpFoundation;\n\nfinal class ActivityController extends Controller implements CommentContextInterface\n{\n // Number of minutes to look back on activities. i.e. a timeout on activity duration.\n private const int LOOK_BACK = 180;\n\n public function __construct(\n private ProviderRegistry $providerRegistry,\n private ActivityService $activityService,\n Response $response,\n private UserService $userService,\n private ActivitySearch\\Service\\ActivitySearch $activitySearch,\n private NudgeFactoryInterface $nudgeFactory,\n private ActivityCommentService $activityCommentService,\n private LoggerInterface $logger,\n private readonly CoachingFeedbackRepository $coachingFeedbackRepository,\n private readonly TeamRepository $teamRepository,\n ) {\n parent::__construct($response);\n }\n\n public static function getCommentImplementation(): string\n {\n return Comment::class;\n }\n\n public function delete()\n {\n $this->request->validate([\n '*' => 'uuid:activities',\n ]);\n\n $deletedIds = [];\n foreach ($this->request->all() as $activityId) {\n $activity = Activity::idOrUuId($activityId);\n\n try {\n if ($this->authorize('delete', $activity)) {\n $activity->delete();\n $deletedIds[] = $activityId;\n\n \\Log::info('Soft deleted activity ' . $activity->id_string . ' by user ' . $this->getUser()->id);\n }\n } catch (AuthorizationException $authorizationException) {\n // They didn't have permission.\n }\n }\n\n return $this->response->withArray($deletedIds);\n }\n\n public function update(Request $request, Activity $activity)\n {\n $this->authorize('updateMetadata', $activity);\n\n $request->validate([\n 'title' => 'string|max:250',\n 'category_id' => 'uuid:playbook_categories',\n 'language' => [\n new In(\n LanguageDialect::query()\n ->with('language')\n ->cursor()\n ->map(static function (LanguageDialect $languageDialect): string {\n return $languageDialect->getLanguageLocale();\n })\n ->all()\n ),\n ],\n ]);\n\n if ($request->has('title')) {\n $activity->title = $request->input('title');\n }\n\n if ($request->has('category_id')) {\n $category = PlaybookCategory::uuid($request->input('category_id'));\n\n if ($category->playbook->team_id !== $request->user()->team_id) {\n return $this->response->errorNotFound('Sorry, this category does not belong to your playbook.');\n }\n\n $activity->playbook_category_id = $category->id;\n }\n\n if ($request->has('language')) {\n if (! $activity->isInProgress()) {\n return $this->response->withError(\n 'Activity language can only be set while the meeting is in progress.',\n 400\n );\n }\n\n $activity->setLanguageCode($request->input('language'));\n }\n\n $activity->save();\n\n return $this->response->withOk();\n }\n\n // XXX: This should be merged with the update method.\n\n /**\n * @param Activity $activity\n *\n * @throws AuthorizationException\n * @throws SocialAccountTokenInvalidException\n *\n * @return mixed\n */\n public function summarize(Activity $activity): mixed\n {\n $this->logger->info('[Log Activity] Summarizing activity ', [\n 'activityId' => $activity->getUuid(),\n 'payload' => $this->request->all(),\n ]);\n $this->authorize('update', $activity);\n\n $this->logger->info('[Log Activity] Validating summary');\n // Validate the payload.\n $this->validateSummary($activity);\n\n // All objects must belong to this team.\n /** @var User $user */\n $user = $this->request->user();\n $team = $user->getTeam();\n $crmService = $this->providerRegistry->get($team->crm->provider);\n\n try {\n $crmUser = $user;\n if ($user->isCrmRequired() === false) {\n $crmUser = $team->owner;\n }\n $crmService->setUser($crmUser);\n } catch (SocialAccountTokenInvalidException $accountTokenInvalidException) {\n // Return a JSON response with the response array and status code.\n return $this->response->errorWrongArgs($accountTokenInvalidException->getMessage());\n }\n\n $rawEntities = $this->request->input('entities');\n\n /** @var Layout $layout */\n $layout = $team->crm->layouts()->uuid(\n $this->request->input('layout_id')\n );\n\n // Delay execution of CRM jobs to avoid locking issues.\n $jobDelay = 0;\n\n // If we have arrived from a notification, mark it as read.\n $notificationId = $this->request->input('nId');\n if ($notificationId) {\n $notification = $user->unreadNotifications->where('id', $notificationId)->first();\n\n if ($notification) {\n $notification->markAsRead();\n }\n }\n\n $title = $this->request->input('title');\n $prospects = $this->request->input('prospects');\n $opportunityId = $this->request->input('opportunity_id');\n $stageId = $this->request->input('stage_id');\n $categoryId = $this->request->input('category_id');\n $summary = $this->request->input('summary');\n $crmProviderId = $this->request->input('crm_id');\n $isInternal = $this->request->input('is_internal') ?? false;\n\n $lead = null;\n $category = null;\n $account = null;\n $contact = null;\n $opportunity = null;\n $stage = null;\n $callStage = null;\n\n foreach ($prospects as $prospectData) {\n $objectId = $prospectData['id'];\n\n if ($objectId === null) {\n continue;\n }\n\n $objectType = $prospectData['type'];\n $this->logger->info('debug', ['prospect_data' => $prospectData]);\n\n try {\n if ($objectType === null) {\n $this->logger->info('no object type');\n if ($crmService instanceof SupportsObjectTypeParseInterface) {\n $objectType = $crmService->parseObjectType($objectId);\n }\n }\n\n switch ($objectType) {\n case 'lead':\n $this->logger->info('Processing lead');\n /** @var Lead|null $lead */\n $lead = $team->crm->leads()->where('crm_provider_id', $objectId)->first();\n\n // Lead does not exist locally, import it.\n if ($lead === null) {\n $this->logger->info('Lead does not exist locally');\n /** @var Lead $lead */\n $lead = $crmService->syncLead($objectId);\n }\n\n $this->logger->info('Lead found', ['leadId' => $lead->id]);\n $activity->lead_id = $lead->id;\n\n if ($stageId === null) {\n $this->logger->info('Stage ID is null');\n // If it was not provided, just assume it is the current stage.\n $callStage = $lead->stage;\n\n break;\n }\n\n $this->logger->info('Looking for stage');\n // Determine if they have changed the stage.\n /** @var Stage $stage */\n $stage = $team->crm->stages()\n ->uuid($stageId, false)\n ->where('type', Stage::TYPE_LEAD)\n ->firstOrFail();\n\n $this->logger->info('Stage found', ['stageId' => $stage->id, 'lead_stage' => $lead->stage_id]);\n if ($lead->stage_id && $lead->stage_id !== $stage->id) {\n $this->logger->info('Stage has changed');\n // Storage current stage on activity.\n $callStage = $lead->stage;\n\n // The stage has changed, update in remote CRM.\n dispatch(new UpdateStage($activity, $lead, $callStage, $stage));\n\n $this->logger->info(\n sprintf(\n '[%s] User changing lead stage from %s to %s',\n $crmService->getDisplayName(),\n $callStage->getName(),\n $stage->getName()\n ),\n [\n 'user' => $user->getUuid(),\n 'lead' => $lead->getUuid(),\n ]\n );\n } else {\n $this->logger->info('Stage has not changed');\n // Stage remains as current.\n $callStage = $stage;\n }\n\n break;\n\n case 'account':\n $this->logger->info('Processing account');\n // If the object is not a lead, it should be an account.\n $account = $team->crm->accounts()->where('crm_provider_id', $objectId)->first();\n\n // Account does not exist locally, import it.\n if ($account === null) {\n $this->logger->info('Account does not exist locally');\n $account = $crmService->syncAccount($objectId);\n }\n\n $this->logger->info('Account found', ['accountId' => $account->id]);\n\n break;\n case 'contact':\n $this->logger->info('processing contact');\n $contact = $team->crm->contacts()->where('crm_provider_id', $objectId)->first();\n\n // Contact does not exist locally, import it.\n if (! $contact instanceof Contact) {\n $this->logger->info('contact does not exist locally');\n $contact = $crmService->syncContact($objectId);\n }\n\n $this->logger->info('resolving account');\n $account = $this->resolveAccount($team, $contact, $crmService, $prospects);\n\n break;\n }\n\n // If they have specified an opportunity, retrieve this with stage.\n if ($opportunityId) {\n $this->logger->info('opportunity id is set');\n $opportunity = $team->crm->opportunities()->where('crm_provider_id', $opportunityId)->first();\n\n // Opportunity does not exist locally, import it.\n if ($opportunity === null) {\n $this->logger->info('opportunity does not exist locally');\n $opportunity = $crmService->syncOpportunity($opportunityId);\n }\n\n if ($stageId === null) {\n $this->logger->info('stage id is null');\n // If it was not provided, just assume it is the current stage.\n $callStage = $opportunity->stage ?? null;\n } else {\n $this->logger->info('looking for stage');\n /** @var ?Stage $opportunityStage */\n $opportunityStage = $team->crm\n ->stages()\n ->uuid($stageId, false)\n ->where('type', Stage::TYPE_OPPORTUNITY)\n ->first();\n\n // There is a chance we still cannot import this opportunity.\n if ($opportunityStage !== null && $opportunity !== null && $opportunity->stage_id !== $opportunityStage->id) {\n $this->logger->info('opportunity stage has changed');\n // Storage current stage on activity.\n $callStage = $opportunity->stage;\n\n dispatch(new UpdateStage($activity, $opportunity, $callStage, $opportunityStage));\n\n $this->logger->info(\n sprintf(\n '[%s] User changing opportunity stage from %s to %s',\n $crmService->getDisplayName(),\n $callStage->name,\n $opportunityStage->name\n ),\n [\n 'userId' => $user->id_string,\n 'opportunityId' => $opportunity->id_string,\n ]\n );\n } else {\n $this->logger->info('opportunity stage has not changed');\n // Stage remains as current.\n $callStage = $opportunityStage;\n }\n }\n }\n\n if ($crmProviderId) {\n // Cast $crmProviderId to string otherwise it won't use database index for some records\n $linkedActivity = Activity::where('crm_provider_id', (string) $crmProviderId)->first();\n\n // Check if this activity has already been assigned to a different activity.\n if ($linkedActivity && $linkedActivity->id !== $activity->id) {\n throw new InvalidArgumentException(\n 'Sorry, the linked task has already been logged under a different call. '\n . 'Please choose another linked task.'\n );\n }\n }\n } catch (InvalidArgumentException $exception) {\n $this->logger->error('Failed to process prospect', [\n 'prospect_data' => $prospectData,\n 'reason' => $exception->getMessage(),\n ]);\n\n // Return a JSON response with the response array and status code.\n return $this->response->errorWrongArgs($exception->getMessage());\n } catch (Exception $exception) {\n $this->logger->error('Failed to process prospect', [\n 'prospect_data' => $prospectData,\n 'reason' => $exception->getMessage(),\n ]);\n\n // Return a JSON response with the response array and status code.\n return $this->response->errorInternalError(\n 'Sorry, an error occurred. Please try again or reach out to support if the problem continues.'\n );\n }\n }\n\n if ($categoryId) {\n $category = PlaybookCategory::uuid($categoryId);\n\n if ($category->playbook->team_id !== $team->id) {\n throw new InvalidArgumentException('Sorry, this category does not belong to your playbook.');\n }\n\n $activity->playbook_category_id = $category->id;\n }\n\n $this->logger->info('Prospect data', [\n 'lead_id' => $lead?->getId(),\n 'account_id' => $account?->getId(),\n 'contact_id' => $contact?->getId(),\n 'opportunity_id' => $opportunity?->getId(),\n 'stage_id' => $stage?->getId(),\n ]);\n\n if ($title) {\n $activity->title = $title;\n }\n\n if ($summary) {\n $activity->summary = $summary;\n }\n\n if ($crmProviderId) {\n $activity->crm_provider_id = $crmProviderId;\n }\n\n if ($callStage) {\n $this->logger->info('Setting stage id', ['stageId' => $callStage->id]);\n $activity->stage_id = $callStage->id;\n }\n\n if ($lead) {\n $this->logger->info('Setting lead id', ['leadId' => $lead->id]);\n $activity->lead_id = $lead->id;\n\n // If we are changed from an account > lead, unset the account data.\n $this->logger->info('Unsetting account id, opportunity id, contact id, value');\n $activity->account_id = null;\n $activity->opportunity_id = null;\n $activity->contact_id = null;\n $activity->value = null;\n }\n\n if ($account) {\n $this->logger->info('Setting account id', ['accountId' => $account->id]);\n $activity->account_id = $account->id;\n\n // If we are changed from an lead > account, unset the lead data.\n $this->logger->info('unsetting lead id');\n $activity->lead_id = null;\n\n // Unset the contact if switching different accounts. Will be set up below if still applicable.\n if (! $team->hasFeature(FeatureEnum::LINK_ACTIVITY_TO_MULTIPLE_PROSPECTS) || empty($contact)) {\n $this->logger->info('Unsetting contact id');\n $activity->contact_id = null;\n }\n }\n\n if ($opportunity) {\n $this->logger->info('setting opportunity id', ['opportunityId' => $opportunity->id]);\n $this->logger->info('unsetting lead id');\n $activity->opportunity_id = $opportunity->id;\n $activity->value = $opportunity->value;\n\n // If we are changed from an lead > account, unset the lead data.\n $activity->lead_id = null;\n }\n\n if ($contact) {\n $this->logger->info('setting contact id', ['contactId' => $contact->id]);\n $activity->contact_id = $contact->id;\n\n // If we are changed from an lead > account, unset the lead data.\n $this->logger->info('Unsetting lead id');\n $activity->lead_id = null;\n }\n\n $activity->is_internal = $isInternal;\n $activity->save();\n $activity->refresh();\n\n $this->logger->notice('Activity saved', [\n 'activity_id' => $activity->getId(),\n 'lead_id' => $activity->lead_id,\n 'account_id' => $activity->account_id,\n 'contact_id' => $activity->contact_id,\n 'opportunity_id' => $activity->opportunity_id,\n 'stage_id' => $activity->stage_id,\n 'crm_provider_id' => $activity->getCrmProviderId(),\n ]);\n\n // Store entities as field data on the activity.\n $updatedData = $this->storeEntities($crmService, $activity, $layout, $rawEntities);\n\n if ($activity->isLoggable()) {\n // Follow-up Task or Event data.\n $followupData = $this->fetchFollowupEntities($crmService, $layout, $rawEntities);\n\n $this->logger->info('CRM LOG manual log triggered', [\n 'activityId' => $activity->getUuid(),\n 'followupData' => $followupData,\n 'userId' => $user->getUuid(),\n ]);\n\n // Store data in the CRM.\n // ++add check for crm_required\n $job = new SaveActivity($activity, $followupData);\n\n if ($updatedData) {\n $job->delay(Carbon::now()->addMinutes($jobDelay));\n }\n\n dispatch($job);\n\n // Manually dispatch log for Opportunity or Prospect added\n if ($activity->hasOpportunity() || $activity->hasProspect()) {\n event(new ActivityProspectAdded(\n activity: $activity,\n eventSource: 'manually-log-crm-data'\n ));\n }\n }\n\n return $this->response->withOk();\n }\n\n /**\n * Extract any activity data to be upserted in the Lead/Opportunity/Task etc in the CRM.\n *\n * @param ServiceInterface $service\n * @param Activity $activity\n * @param Layout $layout\n * @param array $entities The raw entity data from user\n *\n * @return array\n */\n private function storeEntities(ServiceInterface $service, Activity $activity, Layout $layout, array $entities): array\n {\n $updatedData = [];\n $existingData = $activity->data()->get();\n\n // We need to delete any existing data to overwrite with latest values.\n $activity->data()->delete();\n\n $layoutEntities = $layout->entities()\n ->with('field', 'parent')\n ->whereHas('field', function ($query) {\n $query->where('is_selectable', 1);\n })\n ->get();\n\n /** @var LayoutEntity $entity */\n foreach ($layoutEntities as $entity) {\n // If the user has provided a value for this entity\n if (array_key_exists($entity->id_string, $entities)) {\n $value = $entities[$entity->id_string];\n\n // Convert raw data into values that the CRM can consume.\n if ($value) {\n $value = $service->normalizeValue($entity->field->type, $value);\n }\n\n // Check the field is part of the activity-summary section.\n if ($entity->parent && $entity->parent->label === 'activity-summary' && $value) {\n // This is the internal database ID, not the external CRM ID.\n $objectId = null;\n\n switch ($entity->field->object_type) {\n case Field::OBJECT_ACCOUNT:\n $objectId = $activity->account_id;\n\n break;\n\n case Field::OBJECT_CONTACT:\n $objectId = $activity->contact_id;\n\n break;\n\n case Field::OBJECT_OPPORTUNITY:\n $objectId = $activity->opportunity_id;\n\n break;\n\n case Field::OBJECT_LEAD:\n $objectId = $activity->lead_id;\n\n break;\n\n case Field::OBJECT_TASK:\n case Field::OBJECT_EVENT:\n $objectId = $activity->id;\n\n break;\n }\n\n if ($objectId) {\n /** @var FieldData $data */\n $data = $activity->data()->create([\n 'crm_layout_entity_id' => $entity->id,\n 'crm_field_id' => $entity->crm_field_id,\n 'object_type' => $entity->field->object_type,\n 'object_id' => $objectId,\n 'value' => $value,\n ]);\n\n // Never send read-only field data to the CRM.\n if ($entity->read_only === false && $entity->is_visible) {\n $existingValue = $existingData\n ->where('crm_layout_entity_id', $entity->id)\n ->where('crm_field_id', $entity->crm_field_id)\n ->where('object_type', $entity->field->object_type)\n ->where('object_id', $objectId)\n ->first();\n\n // If the field was actually changed, we need to reflect this in the CRM too.\n if ($existingValue === null || $existingValue->value !== $value) {\n $updatedData[] = $data->id;\n }\n }\n }\n }\n }\n }\n\n return $updatedData;\n }\n\n /**\n * Extract any followup data to be dispatched in a job to create a new Task/Event in the CRM.\n *\n * @param ServiceInterface $crmService\n * @param Layout $layout\n * @param array $entities The raw entity data from user\n *\n * @return array\n */\n private function fetchFollowupEntities(ServiceInterface $crmService, Layout $layout, array $entities): array\n {\n $fieldData = [];\n foreach ($entities as $entityId => $value) {\n // Only bother with fields that have a value.\n if ($value) {\n // Extract the entity from the UUID. Check the field is valid and part of the follow-up section.\n $entity = $layout->entities()\n ->uuid($entityId, false)\n ->whereHas('parent', function ($query) {\n $query->where('label', 'follow-up');\n })\n ->whereHas('field', function ($query) {\n $query->where('is_selectable', 1);\n })\n ->first();\n\n if ($entity) {\n // Convert raw data into values that the CRM can consume.\n $value = $crmService->normalizeValue($entity->field->type, $value);\n\n // Add the field and value to the payload.\n $fieldData += [\n $entity->field->crm_provider_id => $value,\n ];\n }\n }\n }\n\n return $fieldData;\n }\n\n /**\n * @param Activity $activity\n */\n private function validateSummary(Activity $activity): void\n {\n $team = $activity->user->team;\n $crmProvider = $team->crm->provider;\n $attributes = [];\n\n $rules = [\n 'layout_id' => 'required|uuid:crm_layouts,crm_configuration_id,' . $team->crm_id,\n 'title' => 'string|max:250',\n 'prospects' => 'required|array',\n 'opportunity_id' => new CrmReference($crmProvider),\n 'category_id' => 'uuid:playbook_categories|required_unless:is_internal,true',\n 'stage_id' => 'uuid:stages,team_id,' . $team->id, // Todo: move to proper validator\n 'summary' => 'max:50000',\n 'nId' => 'exists:notifications,id',\n 'crm_id' => new CrmReference($crmProvider),\n 'entities' => 'array',\n 'is_internal' => 'boolean',\n ];\n\n /** @var Layout $layout */\n $layout = $team->crm->layouts()->uuid($this->request->input('layout_id'));\n\n // Only validate fields, not headers etc. If not loggable, we don't care about follow-up section.\n $entities = $layout->entities()\n ->where('read_only', 0)\n ->whereHas('field', function ($query) {\n $query->where('is_selectable', 1);\n })\n ->whereHas('parent', function ($query) use ($activity) {\n if ($activity->isLoggable() === false) {\n $query->where('label', '<>', 'follow-up');\n }\n });\n\n $isInternal = $this->request->input('is_internal', false);\n\n foreach ($entities->get() as $entity) {\n $rules += $this->buildFieldValidator($entity, $isInternal);\n $attributes += $this->buildFieldMessage($entity);\n }\n\n $this->request->validate($rules, [], $attributes);\n }\n\n private function buildFieldValidator(LayoutEntity $entity, bool $isInternal): array\n {\n return [\n 'entities.' . $entity->id_string => $entity->getValidator($isInternal),\n ];\n }\n\n /**\n * @param LayoutEntity $entity\n *\n * @return array\n */\n private function buildFieldMessage(LayoutEntity $entity): array\n {\n $label = $entity->label;\n if ($label === null) {\n $label = $entity->field->label;\n }\n\n return [\n 'entities.' . $entity->id_string => $label,\n ];\n }\n\n public function search(Request $request, ElasticActivityRepository $repository): JsonResponse\n {\n /** @var User $user */\n $user = $request->user();\n\n $this->debugLog(\n $user,\n 'User extracted from request',\n ['user' => $user->getId(), 'tz' => $user->getTimezone()]\n );\n\n $searchCriteria = Criteria::createFromRequest($request->all(), $user->getTimezone());\n\n $this->debugLog(\n $user,\n 'ActivitySearch criteria built',\n ['searchCriteria' => $searchCriteria]\n );\n\n $filterSet = $this->activitySearch->getHomepageFilterSet($searchCriteria, $user);\n\n $this->debugLog($user, 'FilterSet built', ['filterSet' => $filterSet]);\n\n $this->validateSearch($request, $filterSet);\n\n $this->debugLog($user, 'Request validated');\n\n $searchResponse = $repository->onDemandSearch($user, $searchCriteria, $filterSet);\n\n /** @var Collection<Activity> $activities */\n $activities = $searchResponse['results'];\n\n $this->debugLog($user, 'Activities ES response extracted');\n\n $hideInternalMeetingsSetting = $this->teamRepository->getTeamSettingByTeamId(\n $user->getTeamId(),\n TeamSetting::HIDE_INTERNAL_SCHEDULED_MEETINGS->name(),\n );\n\n if ($hideInternalMeetingsSetting?->getValue() === '1') {\n $activities = $activities->filter(function (Activity $activity) {\n if ($activity->is_internal && empty($activity->actual_start_time)) {\n return false;\n }\n\n return true;\n });\n }\n\n $this->debugLog($user, 'Internal meetings (?!) filtered');\n\n $this->response->getManager()\n ->parseIncludes([\n 'category',\n 'organizer.group',\n 'prospect',\n 'stage',\n 'opportunity',\n 'stats',\n 'scorecards',\n 'masterTrack',\n 'activeParticipants',\n 'notification',\n ])\n ->setSerializer(new JsonSerializer());\n\n $transformerExcludes = $this->request->input('exclude');\n if ($transformerExcludes) {\n $this->response->getManager()->parseExcludes($transformerExcludes);\n }\n\n $this->debugLog($user, 'Response Manager (?!) applied');\n\n $transformer = new ActivityTransformer();\n $transformer->setConsumer($user);\n\n $this->debugLog($user, 'Activity Transformer added');\n\n $resource = new \\League\\Fractal\\Resource\\Collection($activities, $transformer);\n $page = $searchCriteria->getPageNumber();\n\n $this->debugLog($user, 'Search criteria page number called', ['page' => $page]);\n\n $histogram = array_pluck(array_get($searchResponse, 'histogram.buckets', []), 'doc_count', 'key_as_string');\n\n $this->debugLog($user, 'Histogram generated. Response is ready.', ['histogram' => $histogram]);\n\n return $this->response->withArray([\n 'pagination' => [\n 'total' => $searchResponse['totalHits'],\n 'current' => $page,\n 'prev' => max($page - 1, 1),\n 'next' => $page + 1,\n ],\n 'results' => $this->response->getManager()->createData($resource)->toArray(),\n 'histogram' => $histogram,\n ]);\n }\n\n private function debugLog(User $user, string $logMessage, ?array $context = []): void\n {\n // Debug for Learning People Only\n if ($user->getTeamId() !== 260) {\n return;\n }\n\n Log::notice(\n sprintf('[activity-search-controller] %s', $logMessage),\n $context\n );\n }\n\n /** @throws ValidationException */\n private function validateSearch(Request $request, FilterDefinitionCollection $filterSet, ?string $prefix = null): void\n {\n $rules = [\n 'exclude' => 'array',\n 'limit' => 'integer|min:1|max:50',\n 'page' => 'integer|min:1',\n ];\n\n if ($prefix !== null && mb_strpos($prefix, '.') !== false) {\n $rules[rtrim($prefix, '.')] = sprintf(\n 'required|array|max:%d',\n $filterSet->count()\n );\n }\n\n $validationRules = $filterSet->getValidationRules($prefix)\n ->merge($rules)\n ->all();\n\n $request->validate($validationRules);\n }\n\n public function createActivitySearch(Request $request, SearchTransformer $searchTransformer): JsonResponse\n {\n /** @var User $user */\n $user = $request->user();\n\n $search = $this->updateOrCreateActivitySearch($request);\n\n $this->response\n ->getManager()\n ->setSerializer(new JsonSerializer());\n\n return $this->response->withItem(\n $search,\n $searchTransformer\n ->withConsumer($user)\n );\n }\n\n public function updateActivitySearch(Request $request, Search $search): JsonResponse\n {\n $this->authorize('update', $search);\n\n $this->updateOrCreateActivitySearch($request, $search);\n\n return $this->response->withOk();\n }\n\n private function storeNamedSearchFilters(\n Collection $request,\n Search $search,\n FilterDefinitionCollection $filterSet,\n ?string $prefix = null,\n ): self {\n $arrayTypeProperties = $filterSet\n ->getPropertyTypes([\n FilterDefinitionCollection::PROPERTY_TYPE_ARRAY,\n ])\n ->all();\n\n $supportedRequestProperties = $filterSet->getSupportedRequestProperties($prefix);\n\n foreach ($supportedRequestProperties as $requestPropertyName) {\n if (! array_has($request, $requestPropertyName)) {\n continue;\n }\n\n /** @var string|string[] $propertyValue */\n $propertyValue = array_get($request, $requestPropertyName);\n $propertyName = $prefix === null\n ? $requestPropertyName\n : mb_substr($requestPropertyName, mb_strlen($prefix));\n\n $isArrayType = array_has($arrayTypeProperties, $propertyName);\n\n if (! $isArrayType) {\n /** @var string $requestPropertyValue */\n\n $search->filters()->updateOrCreate(\n [\n 'filter' => $propertyName,\n ],\n [\n 'value' => $propertyValue,\n ]\n );\n\n continue;\n }\n\n /** @var string[] $requestPropertyValue */\n\n /** @var SearchFilter[]|Collection $existingFilterValues */\n $existingFilterValuesKeyed = $search->filters()\n ->where('filter', $propertyName)\n ->get()\n ->keyBy('id');\n\n // Iterate over values provided as request parameters\n foreach ($propertyValue as $value) {\n /** @var SearchFilter|null $valueFilter */\n $valueFilter = $search->filters()\n ->where(\n [\n 'filter' => $propertyName,\n 'value' => $value,\n ]\n )\n ->first();\n\n if ($valueFilter !== null) {\n // Remove filter value pair from list to be deleted\n $existingFilterValuesKeyed->forget($valueFilter->id);\n } else {\n // Add new filter/value pair\n $search->filters()->updateOrCreate([\n 'filter' => $propertyName,\n 'value' => $value,\n ]);\n }\n }\n\n // Delete filter value pairs for this filter that no longer exist in request parameters\n foreach ($existingFilterValuesKeyed as $existingFilter) {\n $existingFilter->delete();\n }\n }\n\n /** @var Collection<int, SearchFilter> $filtersKeyed */\n $filtersKeyed = $search->filters()->get()->keyBy('filter');\n\n // wipe removed filters from this search\n foreach ($filtersKeyed as $filterName => $filter) {\n if (array_has($request, $prefix . $filterName)) {\n continue;\n }\n\n // Remove all filter values for this filter\n $search->filters()->where('filter', $filterName)->delete();\n }\n\n return $this;\n }\n\n /**\n * @throws AuthorizationException\n */\n public function fetchActivitySearch(\n Search $search,\n Request $request,\n SearchTransformer $searchTransformer,\n ): JsonResponse {\n $this->authorize('view', $search);\n\n /** @var User $user */\n $user = $request->user();\n\n $this->response\n ->getManager()\n ->setSerializer(new JsonSerializer());\n\n return $this->response->withItem(\n $search,\n $searchTransformer\n ->withConsumer($user)\n );\n }\n\n public function listActivitySearch(Request $request, SearchTransformer $searchTransformer): JsonResponse\n {\n /** @var User $user */\n $user = $request->user();\n\n $this->response\n ->getManager()\n ->setSerializer(new JsonSerializer());\n\n return $this->response->withCollection(\n $user->searches()->get(),\n $searchTransformer\n ->withConsumer($user)\n );\n }\n\n /**\n * Deletes a saved search\n *\n * @param Request $request\n * @param Search $search\n *\n * @throws Exception\n *\n * @return JsonResponse\n */\n public function deleteActivitySearch(Request $request, Search $search): JsonResponse\n {\n $this->authorize('delete', $search);\n\n // Disable and orphan any AutomatedReports that use this search\n $search->automatedReports()->withTrashed()->update([\n 'activity_search_id' => null,\n 'status' => false,\n ]);\n\n // Delete filters and the search itself\n $search->filters()->delete();\n $search->delete();\n\n return $this->response->withOk();\n }\n\n public function live(Request $request, ElasticActivityRepository $repository): JsonResponse\n {\n $user = $this->getUserFromRequest($request);\n\n $this->request->validate([\n 'sort_direction' => 'in:asc,desc',\n 'limit' => 'integer|min:1|max:50',\n 'page' => 'integer|min:1',\n ]);\n\n $activities = $repository->getLiveCoachingEligibleActivities(\n user: $user,\n lookBackMinutes: self::LOOK_BACK,\n limit: (int) $this->request->input('limit', 25),\n page: (int) $this->request->input('page', 1),\n sortBy: ['actual_start_time', 'scheduled_start_time'],\n sortDirection: (string) $this->request->input('sort_direction', 'asc'),\n );\n\n $this->response\n ->getManager()\n ->parseIncludes(['organizer.group', 'prospect'])\n ->setSerializer(new JsonSerializer());\n\n return $this->response->withCollection($activities, new ActivityTransformer());\n }\n\n /**\n * @param Activity $activity\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function show(Activity $activity, ActivityService $activityService): JsonResponse\n {\n $this->authorize('show', $activity);\n\n $user = $activity->getUser();\n $team = $user->getTeam();\n\n // Sync the opportunity with the latest data if possible.\n if ($activity->opportunity_id) {\n try {\n $crmService = $this->providerRegistry->get($team->crm->provider);\n\n if (! $user->isCrmRequired()) {\n $crmService->setUser($team->getOwner());\n } else {\n $crmService->setUser($user);\n }\n\n $crmService->syncOpportunity($activity->opportunity->crm_provider_id);\n } catch (Exception $exception) {\n // Move on.\n }\n }\n\n $activityData = $activityService->getActivityData($this->request->user(), $activity);\n\n return response()->json($activityData);\n }\n\n public function createRecording(Activity $activity)\n {\n $this->authorize('record', $activity);\n\n if ($activity->hasRecordingReasonComplianceRestricted()) {\n return $this->response->errorGone('Recording this number has been disabled by your organization.');\n }\n\n // Tell Twilio to start recording this activity.\n if ($activity->recording_state === Activity::RECORDING_OFF) {\n $job = (new StartRecording($activity))->onQueue(Constants::QUEUE_CONFERENCES);\n dispatch($job);\n\n return $this->response->withCreated();\n }\n\n return $this->response->errorGone('Activity is already recording.');\n }\n\n public function updateRecording(Request $request, Activity $activity)\n {\n $this->authorize('record', $activity);\n\n $request->validate([\n 'preference' => 'boolean',\n 'state' => [\n 'string',\n Rule::in([\n Activity::RECORDING_IN_PROGRESS,\n Activity::RECORDING_PAUSED,\n ]),\n ],\n ]);\n\n if ($request->has('state')) {\n if ($activity->hasRecordingReasonComplianceRestricted()) {\n return $this->response->errorGone('Recording this number has been disabled by your organization.');\n }\n\n // Toggle the recording state between paused and resumed.\n if (! $activity->isRecordingState(Activity::RECORDING_OFF)) {\n $job = (new ToggleRecording($activity, $request->input('state')))\n ->onQueue(Constants::QUEUE_CONFERENCES);\n\n dispatch($job);\n\n return $this->response->withOk();\n }\n\n return $this->response->errorGone('Recording is not toggleable.');\n }\n\n if ($request->has('preference')) {\n $activity->update([\n 'recording_preference' => $request->input('preference') ? 1 : 0,\n ]);\n\n return $this->response->withOk();\n }\n\n return $this->response->errorWrongArgs('Something went wrong');\n }\n\n public function stopRecording(Activity $activity)\n {\n $this->authorize('stopRecord', $activity);\n\n // Tell Twilio to stop recording this activity.\n if ($activity->isRecordingState(Activity::RECORDING_IN_PROGRESS)) {\n $job = (new StopRecording($activity))->onQueue(Constants::QUEUE_CONFERENCES);\n dispatch($job);\n\n return $this->response->withOk();\n }\n\n return $this->response->errorGone('Activity is not recording.');\n }\n\n /**\n * Add activity to this user's favorites playlist\n *\n * @throws AuthorizationException\n */\n public function favorite(Activity $activity, PlaylistActivityRepository $playlistActivityRepository): JsonResponse\n {\n $this->authorize('favorite', $activity);\n\n $user = $this->getUserFromRequest($this->request);\n $favorite = $activity->wasFavoritedBy($user);\n $name = $activity->activity_title ?? '';\n\n // It needs to check at least one record.\n if (! $favorite) {\n $favoritePlaylist = $user->favoritePlaylist();\n\n $playlistActivity = $playlistActivityRepository->findByBaseActivityUserAndPlaylist(\n $activity,\n $user,\n $favoritePlaylist\n );\n\n if ($playlistActivity !== null) {\n $playlistActivity->update(\n // Just update, don't sort.\n ['start_time' => 0, 'name' => mb_strimwidth($name, 0, 100)],\n );\n } else {\n $playlistActivity = $activity->playlistActivities()->create([\n 'playlist_id' => $favoritePlaylist->getId(),\n 'user_id' => $user->getId(),\n 'start_time' => 0,\n 'name' => mb_strimwidth($name, 0, 100),\n ]);\n // Sort it on top.\n $playlistActivity->update(\n [\n 'sort' => $playlistActivityRepository->calculateNewSortOrder(\n null,\n $playlistActivity,\n ),\n ],\n );\n }\n\n $playlistActivityRepository->calculateNewSortOrder(null, $playlistActivity);\n\n return new JsonResponse([], JsonResponse::HTTP_CREATED);\n }\n\n return new JsonResponse(\n [\n 'error' => [\n 'code' => AbstractResponse::CODE_CONFLICT,\n 'http_code' => JsonResponse::HTTP_CONFLICT,\n 'message' => 'Resource Already Exists',\n ],\n ],\n JsonResponse::HTTP_CONFLICT,\n );\n }\n\n /**\n * Remove activity from this user's favorites playlist\n *\n * @param Activity $activity\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function unfavorite(Activity $activity)\n {\n $user = $this->request->user();\n\n $favorites = $activity->favoritedBy($user);\n\n if ($favorites && $favorites->isEmpty()) {\n return $this->response->errorNotFound('Favorite not found.');\n }\n\n $this->authorize('unfavorite', [$activity, $favorites]);\n\n // When you unfavorite an activity,\n // it should remove all the activities in it, including snippets.\n $isDeleted = $favorites->each(function ($favorite) {\n $favorite->forceDelete();\n });\n\n if ($isDeleted) {\n return $this->response->withNoContent();\n }\n\n return $this->response->errorGone('Could not remove favorite.');\n }\n\n /**\n * @param Activity $activity\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function notify(Activity $activity)\n {\n $this->authorize('notify', $activity);\n\n $user = $this->request->user();\n\n $existingNotification = $activity->availabilityNotifications()\n ->where('user_id', $user->id)\n ->exists();\n\n if ($existingNotification) {\n return $this->response->errorWrongArgs('Notification is already configured.');\n }\n\n $notification = Activity\\AvailabilityNotification::create([\n 'user_id' => $user->id,\n 'activity_id' => $activity->id,\n ]);\n\n $this->response\n ->getManager()\n ->setSerializer(new JsonSerializer());\n\n return $this->response->withItem($notification, new AvailabilityNotificationTransformer());\n }\n\n /**\n * @param Activity $activity\n * @param Activity\\AvailabilityNotification $notification\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function unnotify(Activity $activity, Activity\\AvailabilityNotification $notification)\n {\n $this->authorize('unnotify', [$activity, $notification]);\n\n if ($notification->sent_at || $notification->delete()) {\n return $this->response->withNoContent();\n }\n\n return $this->response->errorGone('Could not delete notification.');\n }\n\n public function play(Request $request, Activity $activity)\n {\n $this->authorize('stream', $activity);\n\n $request->validate([\n 'start_time' => 'numeric|between:0,' . $activity->duration,\n ]);\n\n $user = $this->getUserFromRequest($request);\n\n $activity->plays()->create([\n 'user_id' => $user->getId(),\n 'start_time' => $request->input('start_time'),\n ]);\n\n return $this->response->withCreated();\n }\n\n /**\n * @param Activity $activity\n *\n * @return mixed\n */\n public function comment(Activity $activity)\n {\n return $this->newComment($activity);\n }\n\n /**\n * @param Activity $activity\n * @param Comment $comment\n *\n * @return mixed\n */\n public function replyComment(Activity $activity, Comment $comment)\n {\n return $this->newComment($activity, $comment);\n }\n\n /**\n * @param Activity $activity\n * @param Comment|null $comment\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n protected function newComment(Activity $activity, ?Comment $comment = null)\n {\n $this->authorize('comment', [$activity, $comment]);\n\n $this->request->validate([\n 'comment' => 'required|between:1,5000',\n 'type' => 'integer|between:0,3',\n 'visibility' => sprintf('nullable|integer|between:1,%d', count(Comment::getVisibilityLevels())),\n //'start_time' => 'numeric|between:0,'.$activity->duration,\n //'end_time' => 'required_with:start_time|greater_than_or_equal:start_time|numeric|between:0,'.$activity->duration,\n ]);\n\n $threadStartId = null;\n if ($comment) {\n $threadStartId = $comment->thread_start_id ?: $comment->id;\n }\n\n try {\n $newComment = Comment::create([\n 'parent_comment_id' => $comment->id ?? null,\n 'thread_start_id' => $threadStartId,\n 'activity_id' => $activity->id,\n 'user_id' => $this->request->user()->id,\n 'comment' => trim($this->request->input('comment')),\n 'start_time' => $this->request->input('start_time', 0),\n 'end_time' => $this->request->input('end_time', 0),\n 'type' => $this->request->input('type', Comment::TYPE_NEUTRAL),\n 'visibility' => $this->request->input('visibility', Comment::VISIBILITY_PUBLIC),\n ]);\n\n $this->response\n ->getManager()\n ->parseIncludes(['activity'])\n ->setSerializer(new JsonSerializer());\n\n return $this->response->withItem($newComment, new ActivityCommentTransformer());\n } catch (Exception $exception) {\n Sentry::captureException($exception);\n\n return $this->response->errorInternalError('Could not create comment.' . $exception->getMessage());\n }\n }\n\n /**\n * @param Activity $activity\n * @param Comment $comment\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function updateComment(Activity $activity, Comment $comment)\n {\n $this->authorize('comment', [$activity, $comment]);\n\n $this->request->validate([\n 'comment' => 'required|between:1,5000',\n //'start_time' => 'numeric|between:0,'.$activity->duration,\n //'end_time' => 'required_with:start_time|greater_than_or_equal:start_time|numeric|between:0,'.$activity->duration,\n ]);\n\n try {\n $comment->update([\n 'comment' => trim($this->request->input('comment')),\n ]);\n\n $this->response\n ->getManager()\n ->setSerializer(new JsonSerializer());\n\n return $this->response->withOk();\n } catch (Exception $exception) {\n Sentry::captureException($exception);\n\n return $this->response->errorInternalError('Could not update comment.');\n }\n }\n\n public function updateCommentVisibility(Activity $activity, Comment $comment)\n {\n $this->authorize('comment', [$activity, $comment]);\n\n $this->request->validate([\n 'visibility' => sprintf('integer|between:1,%d', count(Comment::getVisibilityLevels())),\n ]);\n\n $visibility = $this->request->input('visibility');\n\n if ($comment->parent !== null) {\n return $this->response->errorWrongArgs('Comment visibility can only be updated on top level comments.');\n }\n\n try {\n $this->activityCommentService->updateCommentVisibility($comment, $visibility);\n\n $this->response\n ->getManager()\n ->setSerializer(new JsonSerializer());\n\n return $this->response->withOk();\n } catch (Exception $exception) {\n Sentry::captureException($exception);\n\n return $this->response->errorInternalError('Could not update comment\\'s visibility.');\n }\n }\n\n /**\n * @param Activity $activity\n * @param Comment $comment\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function deleteComment(Activity $activity, Comment $comment)\n {\n $this->authorize('deleteComment', [$activity, $comment]);\n\n // Delete comment and any children.\n $comment->delete();\n\n return $this->response->withNoContent();\n }\n\n /**\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function fetchComments()\n {\n $user = $this->request->user();\n $this->request->validate([\n 'forUserId' => 'uuid:users,team_id,' . $user->team_id,\n 'types' => 'array',\n 'types.*' => 'integer|between:0,3',\n ]);\n $forUser = null;\n\n $types = [Comment::TYPE_NEUTRAL, Comment::TYPE_GAME_CHANGER, Comment::TYPE_POSITIVE];\n $user = $this->request->user();\n if ($this->request->has('forUserId')) {\n $forUser = $user->team->users()->uuid($this->request->input('forUserId'));\n }\n\n $comments = Comment::query()\n ->whereHas('activity', static function (Builder $builder) use ($user, $forUser): void {\n $builder\n // I left feedback on my own activity; or\n ->where('activities.user_id', $user->getId());\n if ($forUser) {\n // I left feedback on any activity for this user.\n $builder->orWhere([\n 'user_id' => $user->getId(),\n 'activities.user_id' => $forUser->getId(),\n ]);\n }\n })\n ->whereIn('type', $this->request->input('types', $types))\n ->orderBy('created_at', 'desc')\n ->get();\n\n $this->response\n ->getManager()\n ->parseIncludes(['activity', 'user'])\n ->setSerializer(new JsonSerializer());\n\n return $this->response->withCollection($comments, new ActivityCommentTransformer());\n }\n\n public function deleteCoachingFeedback(Activity $activity, CoachingFeedback $coachingFeedback)\n {\n $this->authorize('deleteCoachingFeedback', [$activity, $coachingFeedback]);\n $activity = $coachingFeedback->getActivity();\n\n if ($coachingFeedback->delete()) {\n event(new UpdateSingleEntity(\n entityId: $activity->getId(),\n updateTarget: UpdateTargetEnum::ACTIVITY,\n purpose: 'delete-coaching-feedback',\n ));\n\n return $this->response->withOk();\n }\n\n return $this->response->withError('Delete operation failed. Contact support.', 500);\n }\n\n /**\n * Add new or update Coaching feedback\n *\n * @param Activity $activity\n *\n * @throws AuthorizationException\n * @throws \\Illuminate\\Validation\\ValidationException\n *\n * @return mixed\n */\n public function putCoachingFeedback(Request $request, Activity $activity)\n {\n $user = $request->user();\n\n if (! $user instanceof User) {\n abort(403);\n }\n $teamId = $user->getTeamId();\n\n $this->authorize('coach', $activity);\n\n $this->request->validate([\n 'coach_id' => 'required|uuid:users,team_id,' . $teamId,\n 'coachee_id' => 'required|uuid:users,team_id,' . $teamId,\n 'visibility' => ['required', Rule::in(CoachingFeedback::VISIBILITIES)],\n 'coaching_sections.*.uuid' => 'required|uuid:coaching_sections',\n 'coaching_sections.*.score' => ['required', Rule::in(CoachingSectionFeedback::SCORES)],\n 'coaching_sections.*.summary' => 'string|max:10000',\n 'coaching_sections.*.criteria.*.uuid' => 'required|uuid:coaching_section_criteria',\n 'coaching_sections.*.criteria.*.note' => 'required|string|max:10000',\n 'sharedWithUsers' => [\n 'required_if:visibility,' . CoachingFeedback::VISIBLE_TO_SPECIFIC_USERS,\n 'array',\n ],\n 'sharedWithUsers.*' => [\n 'uuid:users,team_id,' . $teamId,\n ],\n ]);\n\n /** @var User $coach */\n $coach = User::uuid($this->request->input('coach_id'));\n /** @var User $coachee */\n $coachee = User::uuid($this->request->input('coachee_id'));\n $coachingSectionFeedbacks = $this->request->input('coaching_sections');\n\n $previousRecord = $this->coachingFeedbackRepository->getOneForActivityByCoacheeAndCoach(\n $coachee->getId(),\n $coach->getId(),\n $activity->getId()\n );\n $recordIsNew = false;\n if ($previousRecord === null) {\n $recordIsNew = true;\n }\n\n if (! $coachee->isSameTeamId($coach)) {\n return $this->response->errorForbidden('User not member of your team.');\n }\n\n if (! is_array($coachingSectionFeedbacks) || count($coachingSectionFeedbacks) < 1) {\n return $this->response->withError('At least one Coaching Framework Section shall be scored.', 422);\n }\n\n if (! $activity->participants()->where('participants.user_id', $coachee->id)->exists()) {\n return $this->response->withError('Coached user did not participate activity.', 422);\n }\n\n $visibility = $this->request->input('visibility');\n\n $shouldSendNotification = $recordIsNew;\n if ($recordIsNew === false && $visibility !== $previousRecord->getVisibility()) {\n $shouldSendNotification = true;\n }\n\n /**\n * Create CoachingFeedback\n *\n * @var CoachingFeedback $coachingFeedback\n */\n $coachingFeedback = $activity->coachingFeedbacks()->updateOrCreate(\n [\n 'coach_id' => $coach->id,\n 'coachee_id' => $coachee->id,\n ],\n [\n 'framework_id' => $activity->category->id,\n 'visibility' => $visibility,\n ]\n );\n\n $sharedUserIds = [];\n if ($visibility === CoachingFeedback::VISIBLE_TO_SPECIFIC_USERS) {\n foreach ($this->request->input('sharedWithUsers') as $sharedWithUserUuid) {\n /** @var User $user */\n $user = User::uuid($sharedWithUserUuid);\n $sharedUserIds[] = $user->getId();\n }\n }\n\n $syncResult = $coachingFeedback->customAccessUsers()->sync($sharedUserIds);\n\n $scores = [];\n\n\n /**\n * Create CoachingSectionsFeedbacks.\n *\n * @var CoachingSectionFeedback $coachingSectionFeedback\n */\n foreach ($coachingSectionFeedbacks as $coachingSectionFeedbackInput) {\n $coachingSection = CoachingSection::uuid($coachingSectionFeedbackInput['uuid']);\n $coachingSectionFeedback = $coachingFeedback->sectionFeedbacks()->updateOrCreate(\n [\n 'coaching_section_id' => $coachingSection->id,\n ],\n [\n 'score' => array_get($coachingSectionFeedbackInput, 'score'),\n 'summary' => array_get($coachingSectionFeedbackInput, 'summary') ?? '',\n ]\n );\n\n $scores[] = array_get($coachingSectionFeedbackInput, 'score');\n\n $criteria = array_get($coachingSectionFeedbackInput, 'criteria');\n if (is_array($criteria) && ! empty($criteria)) {\n foreach ($criteria as $criteriaFeedbackInput) {\n $coachingSectionFeedback->criterionFeedbacks()->updateOrCreate(\n [\n 'coaching_section_criterion_id' => CoachingSectionCriterion::uuid(array_get($criteriaFeedbackInput, 'uuid'))\n ->id,\n ],\n ['note' => array_get($criteriaFeedbackInput, 'note')],\n );\n }\n }\n }\n\n $coachingFeedback->average_score = array_sum($scores) / count($scores);\n\n if ($recordIsNew === false && $coachingFeedback->getAverageScore() !== $previousRecord->getAverageScore()) {\n $shouldSendNotification = true;\n }\n if (! empty($syncResult['attached']) || ! empty($syncResult['detached']) || ! empty($syncResult['updated'])) {\n $shouldSendNotification = true;\n }\n\n $coachingFeedback->save();\n // ensure updated at for coaching feedback on section feedback summary added.\n $coachingFeedback->touch();\n\n if ($shouldSendNotification) {\n event(new Coached($coachingFeedback));\n }\n\n Datadog::increment('jiminny.activity.score.update', 1, ['company' => $activity->user->team->slug]);\n\n $this->response\n ->getManager()\n ->setSerializer(new JsonSerializer());\n\n $coachingFeedbackTransformer = new CoachingFeedbackTransformer();\n $coachingFeedbackTransformer->setConsumer($this->getUserFromRequest($request));\n\n return $this->response->withItem($coachingFeedback, $coachingFeedbackTransformer);\n }\n\n\n /**\n * Retrieve category criteria for coaching.\n *\n * @param Activity $activity\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function coachingSections(Activity $activity)\n {\n $this->authorize('coach', $activity);\n\n if ($activity->category === null) {\n return $this->response->errorUnprocessable('Category has not yet been assigned.');\n }\n\n $criteria = $activity\n ->category\n ->coachingSections()\n ->where('is_enabled', 1)\n ->orderBy('sequence', 'asc');\n\n $this->response\n ->getManager()\n ->setSerializer(new JsonSerializer());\n\n return $this->response->withCollection($criteria->get(), new CoachingSectionsTransformer());\n }\n\n /**\n * @throws AuthorizationException\n * @throws ValidationException\n *\n * @return mixed\n */\n public function addToPlaylist(Activity $activity, PlaylistTrackFactoryInterface $playlistTrackFactory)\n {\n $this->request->validate([\n 'playlists' => 'required|array',\n 'playlists.*' => 'uuid:playlists',\n 'start_time' => 'numeric|between:0,' . $activity->duration,\n 'end_time' => 'nullable|greater_than_or_equal:start_time|numeric|between:0,' . $activity->duration,\n 'name' => 'required|max:100',\n ]);\n\n $this->authorize('addToPlaylist', [$activity, $this->request->input('playlists')]);\n\n $startTime = $this->request->input('start_time');\n $endTime = $this->request->input('end_time');\n $name = $this->request->input('name');\n /** @var User $user */\n $user = $this->request->user();\n\n // Get playlist by uuid.\n foreach ($this->request->input('playlists') as $playlistId) {\n // Pull out the playlist model.\n $playlist = Playlist::uuid($playlistId);\n\n $playlistTrackFactory->createTrack($playlist, $user, [\n 'name' => $name,\n 'activity' => $activity,\n 'start_time' => $startTime,\n 'end_time' => $endTime,\n ]);\n }\n\n return $this->response->withOk();\n }\n\n public function share(Request $request, Activity $activity): JsonResponse\n {\n $this->authorize('share', $activity);\n\n $request->validate([\n 'note' => 'string|max:1000',\n 'start_time' => 'numeric|between:0,' . $activity->duration,\n 'end_time' => 'nullable|greater_than_or_equal:start_time|numeric|between:0,' . $activity->duration,\n 'recipients.*.type' => 'in:user,group',\n 'recipients.*.id' => 'string|max:40',\n 'share' => 'string|max:255',\n ]);\n\n $user = $request->user();\n\n $recipients = $request->get('recipients');\n $users = $this->userService->convertRecipientsToUsers($user, $recipients);\n\n $shareData = [\n 'from_user_id' => $user->id,\n 'note' => $request->input('note'),\n 'start_time' => $request->input('start_time'),\n 'end_time' => $request->input('end_time'),\n ];\n\n // Create a share object against a notification provider channel\n if ($request->input('share')) {\n /** @var Share $share */\n $share = $activity->shares()->create(\n array_merge(\n $shareData,\n [\n 'notification_provider_channel' => $request->input('share'),\n ]\n )\n );\n\n // All subsequent shares need to reference this row as parent_share_id\n $shareData['parent_share_id'] = $share->id;\n }\n\n // Create a share object against each recipient\n foreach ($users as $recipient) {\n /** @var Share $share */\n $share = $activity->shares()->create(\n array_merge(\n $shareData,\n [\n 'to_user_id' => $recipient->id,\n ]\n )\n );\n\n // If parent_share_id has been selected yet\n if (! isset($shareData['parent_share_id'])) {\n // All subsequent shares need to reference this row as parent_share_id\n $shareData['parent_share_id'] = $share->id;\n }\n }\n\n return $this->response->withOk();\n }\n\n /**\n * @param Activity $activity\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function coachRequest(Activity $activity)\n {\n $this->authorize('coachRequest', $activity);\n\n $this->request->validate([\n 'note' => 'string|max:1000',\n 'start_time' => 'numeric|between:0,' . $activity->duration,\n 'end_time' => 'nullable|greater_than_or_equal:start_time|numeric|between:0,' . $activity->duration,\n 'coachers.*.type' => 'required|in:user',\n 'coachers.*.id' => 'required',\n ]);\n\n $coachers = $this->request->get('coachers');\n $user = $this->request->user();\n $users = $this->userService->convertRecipientsToUsers($user, $coachers);\n\n foreach ($users as $coacher) {\n CoachRequest::create([\n 'user_id' => $coacher->id,\n 'activity_id' => $activity->id,\n 'note' => $this->request->get('note'),\n 'start_time' => $this->request->get('start_time'),\n 'end_time' => $this->request->get('end_time'),\n ]);\n }\n\n return $this->response->withOk();\n }\n\n public function createActivityTopicTriggers(Activity $activity, LoggerInterface $logger): HttpFoundation\\JsonResponse\n {\n $this->authorize('analyzeTopicTriggers', $activity);\n\n if (! $activity->hasTranscription()) {\n return new HttpFoundation\\JsonResponse(\n [\n 'error' => 'Transcription not found.',\n ],\n JsonResponse::HTTP_NOT_FOUND\n );\n }\n\n $logger->info(__METHOD__ . ': queued for analysis', [\n 'activity' => $activity->id_string,\n ]);\n\n dispatch(new ActivityAnalytics\\Job\\AnalyzeActivityTopicTriggers($activity));\n\n return new HttpFoundation\\JsonResponse(null, JsonResponse::HTTP_CREATED);\n }\n\n public function fetchActivityTopicTriggers(\n Activity $activity,\n LoggerInterface $logger,\n ActivityTopicTriggerTransformer $transformer\n ): HttpFoundation\\JsonResponse {\n $this->authorize('fetchTopicTriggers', $activity);\n\n $logger->debug(__METHOD__, [\n 'activity' => $activity->id_string,\n ]);\n\n if (! $activity->isProcessed()) {\n return new HttpFoundation\\JsonResponse([]);\n }\n\n $payload = [];\n\n if ($activity->hasTopicTriggers()) {\n $payload = $activity->getTopicTriggersSorted()\n ->map(\n static fn (Activity\\TopicTrigger $activityTopicTrigger): array\n => $transformer->transform($activityTopicTrigger)\n )\n ->values()\n ->all();\n }\n\n return new HttpFoundation\\JsonResponse($payload);\n }\n\n /**\n * @param Activity $activity\n * @param StatsTransformer $statsTransformer\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function stats(Activity $activity, StatsTransformer $statsTransformer)\n {\n $this->authorize('stream', $activity);\n\n if (! $activity->hasTranscription()) {\n return $this->response->errorNotFound('Waveform data is not yet generated.');\n }\n\n $this->response\n ->getManager()\n ->parseIncludes(['wavedata'])\n ->setSerializer(new JsonSerializer());\n\n return $this->response->withItem($activity, $statsTransformer);\n }\n\n public function destroy(Activity $activity)\n {\n $this->authorize('delete', $activity);\n\n $activity->delete();\n\n \\Log::info('Soft delete activity ' . $activity->id_string . ' by user ' . $this->getUser()->id);\n\n return $this->response->withNoContent();\n }\n\n public function note(Activity $activity)\n {\n $this->authorize('note', $activity);\n\n $this->request->validate([\n 'note' => 'required|min:1|max:2000',\n 'time' => 'required|numeric|min:0|max:86400',\n ]);\n\n $note = $this->request->input('note');\n $time = $this->request->input('time');\n\n $this->activityService->setActivity($activity);\n $this->activityService->takeNote($this->getUser(), $note, $time);\n\n return $this->response->withCreated();\n }\n\n /**\n * Mark an activity as private.\n *\n * @param Activity $activity\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function markAsPrivate(Activity $activity)\n {\n $this->authorize('markAsPrivate', $activity);\n\n if ($activity->is_private === false) {\n $activity->is_private = true;\n $activity->save();\n\n return $this->response->withOk();\n }\n\n return $this->response->withNoContent();\n }\n\n /**\n * Mark an activity as public.\n *\n * @param Activity $activity\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function markAsPublic(Activity $activity)\n {\n $this->authorize('markAsPublic', $activity);\n\n if ($activity->is_private) {\n $activity->is_private = false;\n $activity->save();\n\n return $this->response->withOk();\n }\n\n return $this->response->withNoContent();\n }\n\n /**\n * @throws LogicException\n */\n public function fetchCloudFrontS3MediaKeys(Activity $activity, PlaybackService $playbackService): JsonResponse\n {\n $masterTrack = $activity->masterTrack()->first();\n\n if (! $masterTrack instanceof Track) {\n throw new LogicException(sprintf('Master track not found for activity \"%s\"', $activity->getUuid()));\n }\n\n return $this->response->withArray(\n $playbackService->generateCookies(\n $masterTrack,\n $this->request->ip(),\n ),\n );\n }\n\n /**\n * @throws ValidationException\n */\n private function updateOrCreateActivitySearch(Request $request, ?Search $search = null): Search\n {\n $request->validate([\n 'name' => 'required|string|min:2|max:100',\n ]);\n\n $user = $this->getUserFromRequest($request);\n\n $searchName = $request->input('name');\n\n if ($search !== null) {\n $search->update([\n 'name' => $searchName,\n ]);\n\n return $search;\n }\n\n $request->validate([\n 'filters' => ['required', 'array', new MultidimensionalArrayMaxCharRule(limit: 255)],\n 'nudges' => 'array|max:' . count(Nudge::MAP_CHANNEL),\n 'nudges.*.channel' => 'required|in:' . implode(',', Nudge::MAP_CHANNEL),\n 'nudges.*.frequency' => 'required|in:' . implode(',', Nudge::MAP_FREQUENCY),\n 'nudges.*.expiresAt' => [\n 'required',\n 'date',\n 'after:today',\n 'before_or_equal:' . now()->addYear()->format('Y-m-d'),\n ],\n ]);\n\n $searchCriteria = Criteria::createFromRequest(\n Collection::make($request->input('filters', []))->all(),\n $user->getTimezone()\n );\n\n $filterSet = $this->activitySearch->getOnDemandPageFilterSet($searchCriteria, $user);\n $this->validateSearch($request, $filterSet, 'filters.');\n\n /** @var Search $search */\n $search = Search::create([\n 'name' => $searchName,\n 'uuid' => Uuid::uuid4()->toString(),\n 'user_id' => $user->getId(),\n ]);\n\n Collection::make($request->input('nudges', []))\n ->each(fn (array $attributes): Nudge => $this->nudgeFactory->createNudge($search, $attributes));\n\n $this->storeNamedSearchFilters(Collection::make($request->all()), $search, $filterSet, 'filters.');\n\n return $search;\n }\n\n private function resolveAccount(\n Team $team,\n Contact $contact,\n ServiceInterface $crmService,\n array $prospects,\n ): ?Account {\n $this->logger->info('Resolving account from contact');\n $account = $contact->getAccount();\n\n if (! $team->hasFeature(FeatureEnum::LINK_ACTIVITY_TO_MULTIPLE_PROSPECTS)) {\n $this->logger->info('Team does not have feature to link activity to multiple prospects');\n\n return $account;\n }\n\n $this->logger->info('Resolving account from prospect data');\n $accountData = array_filter(\n $prospects,\n static fn (array $prospectData): bool => $prospectData['type'] === 'account'\n );\n\n if (! empty($accountData)) {\n $this->logger->info('Found account data in prospects');\n $accountData = reset($accountData);\n\n $account = $team->crm->accounts()->where('crm_provider_id', $accountData['id'])->first();\n\n if (! $account instanceof Account) {\n $this->logger->info('Account not found in database, syncing from CRM');\n $account = $crmService->syncAccount($accountData['id']);\n }\n }\n\n $this->logger->info('Resolved account', ['account' => $account->getId()]);\n\n return $account;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Http\\Controllers\\API;\n\nuse Carbon\\Carbon;\nuse ChaseConey\\LaravelDatadogHelper\\Datadog;\nuse Exception;\nuse Illuminate\\Auth\\Access\\AuthorizationException;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Http\\JsonResponse;\nuse Illuminate\\Http\\Request;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Validation\\Rule;\nuse Illuminate\\Validation\\Rules\\In;\nuse Illuminate\\Validation\\ValidationException;\nuse InvalidArgumentException;\nuse Jiminny\\Component\\ActivityAnalytics;\nuse Jiminny\\Component\\ActivitySearch;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionCollection;\nuse Jiminny\\Component\\PlaybackPage\\Comments\\Services\\ActivityCommentService;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Contracts\\ES\\Events\\UpdateSingleEntity;\nuse Jiminny\\Contracts\\ES\\UpdateTargetEnum;\nuse Jiminny\\Contracts\\Nudge\\NudgeFactoryInterface;\nuse Jiminny\\Contracts\\Playlist\\PlaylistTrackFactoryInterface;\nuse Jiminny\\Contracts\\Repositories\\PlaylistActivityRepository;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Enums\\TeamSetting;\nuse Jiminny\\Events\\Activities\\AiAutomation\\ActivityProspectAdded;\nuse Jiminny\\Events\\Activities\\Coaching\\Coached;\nuse Jiminny\\Contracts\\Services\\Crm\\SupportsObjectTypeParseInterface;\nuse Jiminny\\Exceptions\\LogicException;\nuse Jiminny\\Exceptions\\SocialAccountTokenInvalidException;\nuse Jiminny\\Http\\Controllers\\API\\BaseController as Controller;\nuse Jiminny\\Http\\Controllers\\CommentContextInterface;\nuse Jiminny\\Http\\Responses\\Api\\AbstractResponse;\nuse Jiminny\\Http\\Responses\\Api\\Response;\nuse Jiminny\\Http\\Serializers\\JsonSerializer;\nuse Jiminny\\Http\\Transformers\\ActivityCommentTransformer;\nuse Jiminny\\Http\\Transformers\\ActivityTopicTriggerTransformer;\nuse Jiminny\\Http\\Transformers\\ActivityTransformer;\nuse Jiminny\\Http\\Transformers\\AvailabilityNotificationTransformer;\nuse Jiminny\\Http\\Transformers\\CoachingFeedbackTransformer;\nuse Jiminny\\Http\\Transformers\\CoachingSectionsTransformer;\nuse Jiminny\\Http\\Transformers\\SearchTransformer;\nuse Jiminny\\Http\\Transformers\\StatsTransformer;\nuse Jiminny\\Jobs\\Crm\\SaveActivity;\nuse Jiminny\\Jobs\\Crm\\UpdateStage;\nuse Jiminny\\Jobs\\Telephony\\StartRecording;\nuse Jiminny\\Jobs\\Telephony\\StopRecording;\nuse Jiminny\\Jobs\\Telephony\\ToggleRecording;\nuse Jiminny\\Models\\Account;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Activity\\CoachRequest;\nuse Jiminny\\Models\\Activity\\Comment;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\Activity\\Share;\nuse Jiminny\\Models\\CoachingFeedback;\nuse Jiminny\\Models\\CoachingSection;\nuse Jiminny\\Models\\CoachingSectionCriterion;\nuse Jiminny\\Models\\CoachingSectionFeedback;\nuse Jiminny\\Models\\Contact;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldData;\nuse Jiminny\\Models\\Crm\\Layout;\nuse Jiminny\\Models\\Crm\\LayoutEntity;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\LanguageDialect;\nuse Jiminny\\Models\\Lead;\nuse Jiminny\\Models\\Nudge;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Models\\Playlist;\nuse Jiminny\\Models\\Stage;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\Track;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\CoachingFeedbackRepository;\nuse Jiminny\\Repositories\\ElasticActivityRepository;\nuse Jiminny\\Repositories\\TeamRepository;\nuse Jiminny\\Rules\\CrmReference;\nuse Jiminny\\Rules\\MultidimensionalArrayMaxCharRule;\nuse Jiminny\\Services\\ActivityService;\nuse Jiminny\\Services\\Crm\\ProviderRegistry;\nuse Jiminny\\Services\\PlaybackService;\nuse Jiminny\\Services\\UserService;\nuse Jiminny\\VO\\Repository\\OnDemandActivitySearch\\Criteria;\nuse Psr\\Log\\LoggerInterface;\nuse Ramsey\\Uuid\\Uuid;\nuse Sentry;\nuse Symfony\\Component\\HttpFoundation;\n\nfinal class ActivityController extends Controller implements CommentContextInterface\n{\n // Number of minutes to look back on activities. i.e. a timeout on activity duration.\n private const int LOOK_BACK = 180;\n\n public function __construct(\n private ProviderRegistry $providerRegistry,\n private ActivityService $activityService,\n Response $response,\n private UserService $userService,\n private ActivitySearch\\Service\\ActivitySearch $activitySearch,\n private NudgeFactoryInterface $nudgeFactory,\n private ActivityCommentService $activityCommentService,\n private LoggerInterface $logger,\n private readonly CoachingFeedbackRepository $coachingFeedbackRepository,\n private readonly TeamRepository $teamRepository,\n ) {\n parent::__construct($response);\n }\n\n public static function getCommentImplementation(): string\n {\n return Comment::class;\n }\n\n public function delete()\n {\n $this->request->validate([\n '*' => 'uuid:activities',\n ]);\n\n $deletedIds = [];\n foreach ($this->request->all() as $activityId) {\n $activity = Activity::idOrUuId($activityId);\n\n try {\n if ($this->authorize('delete', $activity)) {\n $activity->delete();\n $deletedIds[] = $activityId;\n\n \\Log::info('Soft deleted activity ' . $activity->id_string . ' by user ' . $this->getUser()->id);\n }\n } catch (AuthorizationException $authorizationException) {\n // They didn't have permission.\n }\n }\n\n return $this->response->withArray($deletedIds);\n }\n\n public function update(Request $request, Activity $activity)\n {\n $this->authorize('updateMetadata', $activity);\n\n $request->validate([\n 'title' => 'string|max:250',\n 'category_id' => 'uuid:playbook_categories',\n 'language' => [\n new In(\n LanguageDialect::query()\n ->with('language')\n ->cursor()\n ->map(static function (LanguageDialect $languageDialect): string {\n return $languageDialect->getLanguageLocale();\n })\n ->all()\n ),\n ],\n ]);\n\n if ($request->has('title')) {\n $activity->title = $request->input('title');\n }\n\n if ($request->has('category_id')) {\n $category = PlaybookCategory::uuid($request->input('category_id'));\n\n if ($category->playbook->team_id !== $request->user()->team_id) {\n return $this->response->errorNotFound('Sorry, this category does not belong to your playbook.');\n }\n\n $activity->playbook_category_id = $category->id;\n }\n\n if ($request->has('language')) {\n if (! $activity->isInProgress()) {\n return $this->response->withError(\n 'Activity language can only be set while the meeting is in progress.',\n 400\n );\n }\n\n $activity->setLanguageCode($request->input('language'));\n }\n\n $activity->save();\n\n return $this->response->withOk();\n }\n\n // XXX: This should be merged with the update method.\n\n /**\n * @param Activity $activity\n *\n * @throws AuthorizationException\n * @throws SocialAccountTokenInvalidException\n *\n * @return mixed\n */\n public function summarize(Activity $activity): mixed\n {\n $this->logger->info('[Log Activity] Summarizing activity ', [\n 'activityId' => $activity->getUuid(),\n 'payload' => $this->request->all(),\n ]);\n $this->authorize('update', $activity);\n\n $this->logger->info('[Log Activity] Validating summary');\n // Validate the payload.\n $this->validateSummary($activity);\n\n // All objects must belong to this team.\n /** @var User $user */\n $user = $this->request->user();\n $team = $user->getTeam();\n $crmService = $this->providerRegistry->get($team->crm->provider);\n\n try {\n $crmUser = $user;\n if ($user->isCrmRequired() === false) {\n $crmUser = $team->owner;\n }\n $crmService->setUser($crmUser);\n } catch (SocialAccountTokenInvalidException $accountTokenInvalidException) {\n // Return a JSON response with the response array and status code.\n return $this->response->errorWrongArgs($accountTokenInvalidException->getMessage());\n }\n\n $rawEntities = $this->request->input('entities');\n\n /** @var Layout $layout */\n $layout = $team->crm->layouts()->uuid(\n $this->request->input('layout_id')\n );\n\n // Delay execution of CRM jobs to avoid locking issues.\n $jobDelay = 0;\n\n // If we have arrived from a notification, mark it as read.\n $notificationId = $this->request->input('nId');\n if ($notificationId) {\n $notification = $user->unreadNotifications->where('id', $notificationId)->first();\n\n if ($notification) {\n $notification->markAsRead();\n }\n }\n\n $title = $this->request->input('title');\n $prospects = $this->request->input('prospects');\n $opportunityId = $this->request->input('opportunity_id');\n $stageId = $this->request->input('stage_id');\n $categoryId = $this->request->input('category_id');\n $summary = $this->request->input('summary');\n $crmProviderId = $this->request->input('crm_id');\n $isInternal = $this->request->input('is_internal') ?? false;\n\n $lead = null;\n $category = null;\n $account = null;\n $contact = null;\n $opportunity = null;\n $stage = null;\n $callStage = null;\n\n foreach ($prospects as $prospectData) {\n $objectId = $prospectData['id'];\n\n if ($objectId === null) {\n continue;\n }\n\n $objectType = $prospectData['type'];\n $this->logger->info('debug', ['prospect_data' => $prospectData]);\n\n try {\n if ($objectType === null) {\n $this->logger->info('no object type');\n if ($crmService instanceof SupportsObjectTypeParseInterface) {\n $objectType = $crmService->parseObjectType($objectId);\n }\n }\n\n switch ($objectType) {\n case 'lead':\n $this->logger->info('Processing lead');\n /** @var Lead|null $lead */\n $lead = $team->crm->leads()->where('crm_provider_id', $objectId)->first();\n\n // Lead does not exist locally, import it.\n if ($lead === null) {\n $this->logger->info('Lead does not exist locally');\n /** @var Lead $lead */\n $lead = $crmService->syncLead($objectId);\n }\n\n $this->logger->info('Lead found', ['leadId' => $lead->id]);\n $activity->lead_id = $lead->id;\n\n if ($stageId === null) {\n $this->logger->info('Stage ID is null');\n // If it was not provided, just assume it is the current stage.\n $callStage = $lead->stage;\n\n break;\n }\n\n $this->logger->info('Looking for stage');\n // Determine if they have changed the stage.\n /** @var Stage $stage */\n $stage = $team->crm->stages()\n ->uuid($stageId, false)\n ->where('type', Stage::TYPE_LEAD)\n ->firstOrFail();\n\n $this->logger->info('Stage found', ['stageId' => $stage->id, 'lead_stage' => $lead->stage_id]);\n if ($lead->stage_id && $lead->stage_id !== $stage->id) {\n $this->logger->info('Stage has changed');\n // Storage current stage on activity.\n $callStage = $lead->stage;\n\n // The stage has changed, update in remote CRM.\n dispatch(new UpdateStage($activity, $lead, $callStage, $stage));\n\n $this->logger->info(\n sprintf(\n '[%s] User changing lead stage from %s to %s',\n $crmService->getDisplayName(),\n $callStage->getName(),\n $stage->getName()\n ),\n [\n 'user' => $user->getUuid(),\n 'lead' => $lead->getUuid(),\n ]\n );\n } else {\n $this->logger->info('Stage has not changed');\n // Stage remains as current.\n $callStage = $stage;\n }\n\n break;\n\n case 'account':\n $this->logger->info('Processing account');\n // If the object is not a lead, it should be an account.\n $account = $team->crm->accounts()->where('crm_provider_id', $objectId)->first();\n\n // Account does not exist locally, import it.\n if ($account === null) {\n $this->logger->info('Account does not exist locally');\n $account = $crmService->syncAccount($objectId);\n }\n\n $this->logger->info('Account found', ['accountId' => $account->id]);\n\n break;\n case 'contact':\n $this->logger->info('processing contact');\n $contact = $team->crm->contacts()->where('crm_provider_id', $objectId)->first();\n\n // Contact does not exist locally, import it.\n if (! $contact instanceof Contact) {\n $this->logger->info('contact does not exist locally');\n $contact = $crmService->syncContact($objectId);\n }\n\n $this->logger->info('resolving account');\n $account = $this->resolveAccount($team, $contact, $crmService, $prospects);\n\n break;\n }\n\n // If they have specified an opportunity, retrieve this with stage.\n if ($opportunityId) {\n $this->logger->info('opportunity id is set');\n $opportunity = $team->crm->opportunities()->where('crm_provider_id', $opportunityId)->first();\n\n // Opportunity does not exist locally, import it.\n if ($opportunity === null) {\n $this->logger->info('opportunity does not exist locally');\n $opportunity = $crmService->syncOpportunity($opportunityId);\n }\n\n if ($stageId === null) {\n $this->logger->info('stage id is null');\n // If it was not provided, just assume it is the current stage.\n $callStage = $opportunity->stage ?? null;\n } else {\n $this->logger->info('looking for stage');\n /** @var ?Stage $opportunityStage */\n $opportunityStage = $team->crm\n ->stages()\n ->uuid($stageId, false)\n ->where('type', Stage::TYPE_OPPORTUNITY)\n ->first();\n\n // There is a chance we still cannot import this opportunity.\n if ($opportunityStage !== null && $opportunity !== null && $opportunity->stage_id !== $opportunityStage->id) {\n $this->logger->info('opportunity stage has changed');\n // Storage current stage on activity.\n $callStage = $opportunity->stage;\n\n dispatch(new UpdateStage($activity, $opportunity, $callStage, $opportunityStage));\n\n $this->logger->info(\n sprintf(\n '[%s] User changing opportunity stage from %s to %s',\n $crmService->getDisplayName(),\n $callStage->name,\n $opportunityStage->name\n ),\n [\n 'userId' => $user->id_string,\n 'opportunityId' => $opportunity->id_string,\n ]\n );\n } else {\n $this->logger->info('opportunity stage has not changed');\n // Stage remains as current.\n $callStage = $opportunityStage;\n }\n }\n }\n\n if ($crmProviderId) {\n // Cast $crmProviderId to string otherwise it won't use database index for some records\n $linkedActivity = Activity::where('crm_provider_id', (string) $crmProviderId)->first();\n\n // Check if this activity has already been assigned to a different activity.\n if ($linkedActivity && $linkedActivity->id !== $activity->id) {\n throw new InvalidArgumentException(\n 'Sorry, the linked task has already been logged under a different call. '\n . 'Please choose another linked task.'\n );\n }\n }\n } catch (InvalidArgumentException $exception) {\n $this->logger->error('Failed to process prospect', [\n 'prospect_data' => $prospectData,\n 'reason' => $exception->getMessage(),\n ]);\n\n // Return a JSON response with the response array and status code.\n return $this->response->errorWrongArgs($exception->getMessage());\n } catch (Exception $exception) {\n $this->logger->error('Failed to process prospect', [\n 'prospect_data' => $prospectData,\n 'reason' => $exception->getMessage(),\n ]);\n\n // Return a JSON response with the response array and status code.\n return $this->response->errorInternalError(\n 'Sorry, an error occurred. Please try again or reach out to support if the problem continues.'\n );\n }\n }\n\n if ($categoryId) {\n $category = PlaybookCategory::uuid($categoryId);\n\n if ($category->playbook->team_id !== $team->id) {\n throw new InvalidArgumentException('Sorry, this category does not belong to your playbook.');\n }\n\n $activity->playbook_category_id = $category->id;\n }\n\n $this->logger->info('Prospect data', [\n 'lead_id' => $lead?->getId(),\n 'account_id' => $account?->getId(),\n 'contact_id' => $contact?->getId(),\n 'opportunity_id' => $opportunity?->getId(),\n 'stage_id' => $stage?->getId(),\n ]);\n\n if ($title) {\n $activity->title = $title;\n }\n\n if ($summary) {\n $activity->summary = $summary;\n }\n\n if ($crmProviderId) {\n $activity->crm_provider_id = $crmProviderId;\n }\n\n if ($callStage) {\n $this->logger->info('Setting stage id', ['stageId' => $callStage->id]);\n $activity->stage_id = $callStage->id;\n }\n\n if ($lead) {\n $this->logger->info('Setting lead id', ['leadId' => $lead->id]);\n $activity->lead_id = $lead->id;\n\n // If we are changed from an account > lead, unset the account data.\n $this->logger->info('Unsetting account id, opportunity id, contact id, value');\n $activity->account_id = null;\n $activity->opportunity_id = null;\n $activity->contact_id = null;\n $activity->value = null;\n }\n\n if ($account) {\n $this->logger->info('Setting account id', ['accountId' => $account->id]);\n $activity->account_id = $account->id;\n\n // If we are changed from an lead > account, unset the lead data.\n $this->logger->info('unsetting lead id');\n $activity->lead_id = null;\n\n // Unset the contact if switching different accounts. Will be set up below if still applicable.\n if (! $team->hasFeature(FeatureEnum::LINK_ACTIVITY_TO_MULTIPLE_PROSPECTS) || empty($contact)) {\n $this->logger->info('Unsetting contact id');\n $activity->contact_id = null;\n }\n }\n\n if ($opportunity) {\n $this->logger->info('setting opportunity id', ['opportunityId' => $opportunity->id]);\n $this->logger->info('unsetting lead id');\n $activity->opportunity_id = $opportunity->id;\n $activity->value = $opportunity->value;\n\n // If we are changed from an lead > account, unset the lead data.\n $activity->lead_id = null;\n }\n\n if ($contact) {\n $this->logger->info('setting contact id', ['contactId' => $contact->id]);\n $activity->contact_id = $contact->id;\n\n // If we are changed from an lead > account, unset the lead data.\n $this->logger->info('Unsetting lead id');\n $activity->lead_id = null;\n }\n\n $activity->is_internal = $isInternal;\n $activity->save();\n $activity->refresh();\n\n $this->logger->notice('Activity saved', [\n 'activity_id' => $activity->getId(),\n 'lead_id' => $activity->lead_id,\n 'account_id' => $activity->account_id,\n 'contact_id' => $activity->contact_id,\n 'opportunity_id' => $activity->opportunity_id,\n 'stage_id' => $activity->stage_id,\n 'crm_provider_id' => $activity->getCrmProviderId(),\n ]);\n\n // Store entities as field data on the activity.\n $updatedData = $this->storeEntities($crmService, $activity, $layout, $rawEntities);\n\n if ($activity->isLoggable()) {\n // Follow-up Task or Event data.\n $followupData = $this->fetchFollowupEntities($crmService, $layout, $rawEntities);\n\n $this->logger->info('CRM LOG manual log triggered', [\n 'activityId' => $activity->getUuid(),\n 'followupData' => $followupData,\n 'userId' => $user->getUuid(),\n ]);\n\n // Store data in the CRM.\n // ++add check for crm_required\n $job = new SaveActivity($activity, $followupData);\n\n if ($updatedData) {\n $job->delay(Carbon::now()->addMinutes($jobDelay));\n }\n\n dispatch($job);\n\n // Manually dispatch log for Opportunity or Prospect added\n if ($activity->hasOpportunity() || $activity->hasProspect()) {\n event(new ActivityProspectAdded(\n activity: $activity,\n eventSource: 'manually-log-crm-data'\n ));\n }\n }\n\n return $this->response->withOk();\n }\n\n /**\n * Extract any activity data to be upserted in the Lead/Opportunity/Task etc in the CRM.\n *\n * @param ServiceInterface $service\n * @param Activity $activity\n * @param Layout $layout\n * @param array $entities The raw entity data from user\n *\n * @return array\n */\n private function storeEntities(ServiceInterface $service, Activity $activity, Layout $layout, array $entities): array\n {\n $updatedData = [];\n $existingData = $activity->data()->get();\n\n // We need to delete any existing data to overwrite with latest values.\n $activity->data()->delete();\n\n $layoutEntities = $layout->entities()\n ->with('field', 'parent')\n ->whereHas('field', function ($query) {\n $query->where('is_selectable', 1);\n })\n ->get();\n\n /** @var LayoutEntity $entity */\n foreach ($layoutEntities as $entity) {\n // If the user has provided a value for this entity\n if (array_key_exists($entity->id_string, $entities)) {\n $value = $entities[$entity->id_string];\n\n // Convert raw data into values that the CRM can consume.\n if ($value) {\n $value = $service->normalizeValue($entity->field->type, $value);\n }\n\n // Check the field is part of the activity-summary section.\n if ($entity->parent && $entity->parent->label === 'activity-summary' && $value) {\n // This is the internal database ID, not the external CRM ID.\n $objectId = null;\n\n switch ($entity->field->object_type) {\n case Field::OBJECT_ACCOUNT:\n $objectId = $activity->account_id;\n\n break;\n\n case Field::OBJECT_CONTACT:\n $objectId = $activity->contact_id;\n\n break;\n\n case Field::OBJECT_OPPORTUNITY:\n $objectId = $activity->opportunity_id;\n\n break;\n\n case Field::OBJECT_LEAD:\n $objectId = $activity->lead_id;\n\n break;\n\n case Field::OBJECT_TASK:\n case Field::OBJECT_EVENT:\n $objectId = $activity->id;\n\n break;\n }\n\n if ($objectId) {\n /** @var FieldData $data */\n $data = $activity->data()->create([\n 'crm_layout_entity_id' => $entity->id,\n 'crm_field_id' => $entity->crm_field_id,\n 'object_type' => $entity->field->object_type,\n 'object_id' => $objectId,\n 'value' => $value,\n ]);\n\n // Never send read-only field data to the CRM.\n if ($entity->read_only === false && $entity->is_visible) {\n $existingValue = $existingData\n ->where('crm_layout_entity_id', $entity->id)\n ->where('crm_field_id', $entity->crm_field_id)\n ->where('object_type', $entity->field->object_type)\n ->where('object_id', $objectId)\n ->first();\n\n // If the field was actually changed, we need to reflect this in the CRM too.\n if ($existingValue === null || $existingValue->value !== $value) {\n $updatedData[] = $data->id;\n }\n }\n }\n }\n }\n }\n\n return $updatedData;\n }\n\n /**\n * Extract any followup data to be dispatched in a job to create a new Task/Event in the CRM.\n *\n * @param ServiceInterface $crmService\n * @param Layout $layout\n * @param array $entities The raw entity data from user\n *\n * @return array\n */\n private function fetchFollowupEntities(ServiceInterface $crmService, Layout $layout, array $entities): array\n {\n $fieldData = [];\n foreach ($entities as $entityId => $value) {\n // Only bother with fields that have a value.\n if ($value) {\n // Extract the entity from the UUID. Check the field is valid and part of the follow-up section.\n $entity = $layout->entities()\n ->uuid($entityId, false)\n ->whereHas('parent', function ($query) {\n $query->where('label', 'follow-up');\n })\n ->whereHas('field', function ($query) {\n $query->where('is_selectable', 1);\n })\n ->first();\n\n if ($entity) {\n // Convert raw data into values that the CRM can consume.\n $value = $crmService->normalizeValue($entity->field->type, $value);\n\n // Add the field and value to the payload.\n $fieldData += [\n $entity->field->crm_provider_id => $value,\n ];\n }\n }\n }\n\n return $fieldData;\n }\n\n /**\n * @param Activity $activity\n */\n private function validateSummary(Activity $activity): void\n {\n $team = $activity->user->team;\n $crmProvider = $team->crm->provider;\n $attributes = [];\n\n $rules = [\n 'layout_id' => 'required|uuid:crm_layouts,crm_configuration_id,' . $team->crm_id,\n 'title' => 'string|max:250',\n 'prospects' => 'required|array',\n 'opportunity_id' => new CrmReference($crmProvider),\n 'category_id' => 'uuid:playbook_categories|required_unless:is_internal,true',\n 'stage_id' => 'uuid:stages,team_id,' . $team->id, // Todo: move to proper validator\n 'summary' => 'max:50000',\n 'nId' => 'exists:notifications,id',\n 'crm_id' => new CrmReference($crmProvider),\n 'entities' => 'array',\n 'is_internal' => 'boolean',\n ];\n\n /** @var Layout $layout */\n $layout = $team->crm->layouts()->uuid($this->request->input('layout_id'));\n\n // Only validate fields, not headers etc. If not loggable, we don't care about follow-up section.\n $entities = $layout->entities()\n ->where('read_only', 0)\n ->whereHas('field', function ($query) {\n $query->where('is_selectable', 1);\n })\n ->whereHas('parent', function ($query) use ($activity) {\n if ($activity->isLoggable() === false) {\n $query->where('label', '<>', 'follow-up');\n }\n });\n\n $isInternal = $this->request->input('is_internal', false);\n\n foreach ($entities->get() as $entity) {\n $rules += $this->buildFieldValidator($entity, $isInternal);\n $attributes += $this->buildFieldMessage($entity);\n }\n\n $this->request->validate($rules, [], $attributes);\n }\n\n private function buildFieldValidator(LayoutEntity $entity, bool $isInternal): array\n {\n return [\n 'entities.' . $entity->id_string => $entity->getValidator($isInternal),\n ];\n }\n\n /**\n * @param LayoutEntity $entity\n *\n * @return array\n */\n private function buildFieldMessage(LayoutEntity $entity): array\n {\n $label = $entity->label;\n if ($label === null) {\n $label = $entity->field->label;\n }\n\n return [\n 'entities.' . $entity->id_string => $label,\n ];\n }\n\n public function search(Request $request, ElasticActivityRepository $repository): JsonResponse\n {\n /** @var User $user */\n $user = $request->user();\n\n $this->debugLog(\n $user,\n 'User extracted from request',\n ['user' => $user->getId(), 'tz' => $user->getTimezone()]\n );\n\n $searchCriteria = Criteria::createFromRequest($request->all(), $user->getTimezone());\n\n $this->debugLog(\n $user,\n 'ActivitySearch criteria built',\n ['searchCriteria' => $searchCriteria]\n );\n\n $filterSet = $this->activitySearch->getHomepageFilterSet($searchCriteria, $user);\n\n $this->debugLog($user, 'FilterSet built', ['filterSet' => $filterSet]);\n\n $this->validateSearch($request, $filterSet);\n\n $this->debugLog($user, 'Request validated');\n\n $searchResponse = $repository->onDemandSearch($user, $searchCriteria, $filterSet);\n\n /** @var Collection<Activity> $activities */\n $activities = $searchResponse['results'];\n\n $this->debugLog($user, 'Activities ES response extracted');\n\n $hideInternalMeetingsSetting = $this->teamRepository->getTeamSettingByTeamId(\n $user->getTeamId(),\n TeamSetting::HIDE_INTERNAL_SCHEDULED_MEETINGS->name(),\n );\n\n if ($hideInternalMeetingsSetting?->getValue() === '1') {\n $activities = $activities->filter(function (Activity $activity) {\n if ($activity->is_internal && empty($activity->actual_start_time)) {\n return false;\n }\n\n return true;\n });\n }\n\n $this->debugLog($user, 'Internal meetings (?!) filtered');\n\n $this->response->getManager()\n ->parseIncludes([\n 'category',\n 'organizer.group',\n 'prospect',\n 'stage',\n 'opportunity',\n 'stats',\n 'scorecards',\n 'masterTrack',\n 'activeParticipants',\n 'notification',\n ])\n ->setSerializer(new JsonSerializer());\n\n $transformerExcludes = $this->request->input('exclude');\n if ($transformerExcludes) {\n $this->response->getManager()->parseExcludes($transformerExcludes);\n }\n\n $this->debugLog($user, 'Response Manager (?!) applied');\n\n $transformer = new ActivityTransformer();\n $transformer->setConsumer($user);\n\n $this->debugLog($user, 'Activity Transformer added');\n\n $resource = new \\League\\Fractal\\Resource\\Collection($activities, $transformer);\n $page = $searchCriteria->getPageNumber();\n\n $this->debugLog($user, 'Search criteria page number called', ['page' => $page]);\n\n $histogram = array_pluck(array_get($searchResponse, 'histogram.buckets', []), 'doc_count', 'key_as_string');\n\n $this->debugLog($user, 'Histogram generated. Response is ready.', ['histogram' => $histogram]);\n\n return $this->response->withArray([\n 'pagination' => [\n 'total' => $searchResponse['totalHits'],\n 'current' => $page,\n 'prev' => max($page - 1, 1),\n 'next' => $page + 1,\n ],\n 'results' => $this->response->getManager()->createData($resource)->toArray(),\n 'histogram' => $histogram,\n ]);\n }\n\n private function debugLog(User $user, string $logMessage, ?array $context = []): void\n {\n // Debug for Learning People Only\n if ($user->getTeamId() !== 260) {\n return;\n }\n\n Log::notice(\n sprintf('[activity-search-controller] %s', $logMessage),\n $context\n );\n }\n\n /** @throws ValidationException */\n private function validateSearch(Request $request, FilterDefinitionCollection $filterSet, ?string $prefix = null): void\n {\n $rules = [\n 'exclude' => 'array',\n 'limit' => 'integer|min:1|max:50',\n 'page' => 'integer|min:1',\n ];\n\n if ($prefix !== null && mb_strpos($prefix, '.') !== false) {\n $rules[rtrim($prefix, '.')] = sprintf(\n 'required|array|max:%d',\n $filterSet->count()\n );\n }\n\n $validationRules = $filterSet->getValidationRules($prefix)\n ->merge($rules)\n ->all();\n\n $request->validate($validationRules);\n }\n\n public function createActivitySearch(Request $request, SearchTransformer $searchTransformer): JsonResponse\n {\n /** @var User $user */\n $user = $request->user();\n\n $search = $this->updateOrCreateActivitySearch($request);\n\n $this->response\n ->getManager()\n ->setSerializer(new JsonSerializer());\n\n return $this->response->withItem(\n $search,\n $searchTransformer\n ->withConsumer($user)\n );\n }\n\n public function updateActivitySearch(Request $request, Search $search): JsonResponse\n {\n $this->authorize('update', $search);\n\n $this->updateOrCreateActivitySearch($request, $search);\n\n return $this->response->withOk();\n }\n\n private function storeNamedSearchFilters(\n Collection $request,\n Search $search,\n FilterDefinitionCollection $filterSet,\n ?string $prefix = null,\n ): self {\n $arrayTypeProperties = $filterSet\n ->getPropertyTypes([\n FilterDefinitionCollection::PROPERTY_TYPE_ARRAY,\n ])\n ->all();\n\n $supportedRequestProperties = $filterSet->getSupportedRequestProperties($prefix);\n\n foreach ($supportedRequestProperties as $requestPropertyName) {\n if (! array_has($request, $requestPropertyName)) {\n continue;\n }\n\n /** @var string|string[] $propertyValue */\n $propertyValue = array_get($request, $requestPropertyName);\n $propertyName = $prefix === null\n ? $requestPropertyName\n : mb_substr($requestPropertyName, mb_strlen($prefix));\n\n $isArrayType = array_has($arrayTypeProperties, $propertyName);\n\n if (! $isArrayType) {\n /** @var string $requestPropertyValue */\n\n $search->filters()->updateOrCreate(\n [\n 'filter' => $propertyName,\n ],\n [\n 'value' => $propertyValue,\n ]\n );\n\n continue;\n }\n\n /** @var string[] $requestPropertyValue */\n\n /** @var SearchFilter[]|Collection $existingFilterValues */\n $existingFilterValuesKeyed = $search->filters()\n ->where('filter', $propertyName)\n ->get()\n ->keyBy('id');\n\n // Iterate over values provided as request parameters\n foreach ($propertyValue as $value) {\n /** @var SearchFilter|null $valueFilter */\n $valueFilter = $search->filters()\n ->where(\n [\n 'filter' => $propertyName,\n 'value' => $value,\n ]\n )\n ->first();\n\n if ($valueFilter !== null) {\n // Remove filter value pair from list to be deleted\n $existingFilterValuesKeyed->forget($valueFilter->id);\n } else {\n // Add new filter/value pair\n $search->filters()->updateOrCreate([\n 'filter' => $propertyName,\n 'value' => $value,\n ]);\n }\n }\n\n // Delete filter value pairs for this filter that no longer exist in request parameters\n foreach ($existingFilterValuesKeyed as $existingFilter) {\n $existingFilter->delete();\n }\n }\n\n /** @var Collection<int, SearchFilter> $filtersKeyed */\n $filtersKeyed = $search->filters()->get()->keyBy('filter');\n\n // wipe removed filters from this search\n foreach ($filtersKeyed as $filterName => $filter) {\n if (array_has($request, $prefix . $filterName)) {\n continue;\n }\n\n // Remove all filter values for this filter\n $search->filters()->where('filter', $filterName)->delete();\n }\n\n return $this;\n }\n\n /**\n * @throws AuthorizationException\n */\n public function fetchActivitySearch(\n Search $search,\n Request $request,\n SearchTransformer $searchTransformer,\n ): JsonResponse {\n $this->authorize('view', $search);\n\n /** @var User $user */\n $user = $request->user();\n\n $this->response\n ->getManager()\n ->setSerializer(new JsonSerializer());\n\n return $this->response->withItem(\n $search,\n $searchTransformer\n ->withConsumer($user)\n );\n }\n\n public function listActivitySearch(Request $request, SearchTransformer $searchTransformer): JsonResponse\n {\n /** @var User $user */\n $user = $request->user();\n\n $this->response\n ->getManager()\n ->setSerializer(new JsonSerializer());\n\n return $this->response->withCollection(\n $user->searches()->get(),\n $searchTransformer\n ->withConsumer($user)\n );\n }\n\n /**\n * Deletes a saved search\n *\n * @param Request $request\n * @param Search $search\n *\n * @throws Exception\n *\n * @return JsonResponse\n */\n public function deleteActivitySearch(Request $request, Search $search): JsonResponse\n {\n $this->authorize('delete', $search);\n\n // Disable and orphan any AutomatedReports that use this search\n $search->automatedReports()->withTrashed()->update([\n 'activity_search_id' => null,\n 'status' => false,\n ]);\n\n // Delete filters and the search itself\n $search->filters()->delete();\n $search->delete();\n\n return $this->response->withOk();\n }\n\n public function live(Request $request, ElasticActivityRepository $repository): JsonResponse\n {\n $user = $this->getUserFromRequest($request);\n\n $this->request->validate([\n 'sort_direction' => 'in:asc,desc',\n 'limit' => 'integer|min:1|max:50',\n 'page' => 'integer|min:1',\n ]);\n\n $activities = $repository->getLiveCoachingEligibleActivities(\n user: $user,\n lookBackMinutes: self::LOOK_BACK,\n limit: (int) $this->request->input('limit', 25),\n page: (int) $this->request->input('page', 1),\n sortBy: ['actual_start_time', 'scheduled_start_time'],\n sortDirection: (string) $this->request->input('sort_direction', 'asc'),\n );\n\n $this->response\n ->getManager()\n ->parseIncludes(['organizer.group', 'prospect'])\n ->setSerializer(new JsonSerializer());\n\n return $this->response->withCollection($activities, new ActivityTransformer());\n }\n\n /**\n * @param Activity $activity\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function show(Activity $activity, ActivityService $activityService): JsonResponse\n {\n $this->authorize('show', $activity);\n\n $user = $activity->getUser();\n $team = $user->getTeam();\n\n // Sync the opportunity with the latest data if possible.\n if ($activity->opportunity_id) {\n try {\n $crmService = $this->providerRegistry->get($team->crm->provider);\n\n if (! $user->isCrmRequired()) {\n $crmService->setUser($team->getOwner());\n } else {\n $crmService->setUser($user);\n }\n\n $crmService->syncOpportunity($activity->opportunity->crm_provider_id);\n } catch (Exception $exception) {\n // Move on.\n }\n }\n\n $activityData = $activityService->getActivityData($this->request->user(), $activity);\n\n return response()->json($activityData);\n }\n\n public function createRecording(Activity $activity)\n {\n $this->authorize('record', $activity);\n\n if ($activity->hasRecordingReasonComplianceRestricted()) {\n return $this->response->errorGone('Recording this number has been disabled by your organization.');\n }\n\n // Tell Twilio to start recording this activity.\n if ($activity->recording_state === Activity::RECORDING_OFF) {\n $job = (new StartRecording($activity))->onQueue(Constants::QUEUE_CONFERENCES);\n dispatch($job);\n\n return $this->response->withCreated();\n }\n\n return $this->response->errorGone('Activity is already recording.');\n }\n\n public function updateRecording(Request $request, Activity $activity)\n {\n $this->authorize('record', $activity);\n\n $request->validate([\n 'preference' => 'boolean',\n 'state' => [\n 'string',\n Rule::in([\n Activity::RECORDING_IN_PROGRESS,\n Activity::RECORDING_PAUSED,\n ]),\n ],\n ]);\n\n if ($request->has('state')) {\n if ($activity->hasRecordingReasonComplianceRestricted()) {\n return $this->response->errorGone('Recording this number has been disabled by your organization.');\n }\n\n // Toggle the recording state between paused and resumed.\n if (! $activity->isRecordingState(Activity::RECORDING_OFF)) {\n $job = (new ToggleRecording($activity, $request->input('state')))\n ->onQueue(Constants::QUEUE_CONFERENCES);\n\n dispatch($job);\n\n return $this->response->withOk();\n }\n\n return $this->response->errorGone('Recording is not toggleable.');\n }\n\n if ($request->has('preference')) {\n $activity->update([\n 'recording_preference' => $request->input('preference') ? 1 : 0,\n ]);\n\n return $this->response->withOk();\n }\n\n return $this->response->errorWrongArgs('Something went wrong');\n }\n\n public function stopRecording(Activity $activity)\n {\n $this->authorize('stopRecord', $activity);\n\n // Tell Twilio to stop recording this activity.\n if ($activity->isRecordingState(Activity::RECORDING_IN_PROGRESS)) {\n $job = (new StopRecording($activity))->onQueue(Constants::QUEUE_CONFERENCES);\n dispatch($job);\n\n return $this->response->withOk();\n }\n\n return $this->response->errorGone('Activity is not recording.');\n }\n\n /**\n * Add activity to this user's favorites playlist\n *\n * @throws AuthorizationException\n */\n public function favorite(Activity $activity, PlaylistActivityRepository $playlistActivityRepository): JsonResponse\n {\n $this->authorize('favorite', $activity);\n\n $user = $this->getUserFromRequest($this->request);\n $favorite = $activity->wasFavoritedBy($user);\n $name = $activity->activity_title ?? '';\n\n // It needs to check at least one record.\n if (! $favorite) {\n $favoritePlaylist = $user->favoritePlaylist();\n\n $playlistActivity = $playlistActivityRepository->findByBaseActivityUserAndPlaylist(\n $activity,\n $user,\n $favoritePlaylist\n );\n\n if ($playlistActivity !== null) {\n $playlistActivity->update(\n // Just update, don't sort.\n ['start_time' => 0, 'name' => mb_strimwidth($name, 0, 100)],\n );\n } else {\n $playlistActivity = $activity->playlistActivities()->create([\n 'playlist_id' => $favoritePlaylist->getId(),\n 'user_id' => $user->getId(),\n 'start_time' => 0,\n 'name' => mb_strimwidth($name, 0, 100),\n ]);\n // Sort it on top.\n $playlistActivity->update(\n [\n 'sort' => $playlistActivityRepository->calculateNewSortOrder(\n null,\n $playlistActivity,\n ),\n ],\n );\n }\n\n $playlistActivityRepository->calculateNewSortOrder(null, $playlistActivity);\n\n return new JsonResponse([], JsonResponse::HTTP_CREATED);\n }\n\n return new JsonResponse(\n [\n 'error' => [\n 'code' => AbstractResponse::CODE_CONFLICT,\n 'http_code' => JsonResponse::HTTP_CONFLICT,\n 'message' => 'Resource Already Exists',\n ],\n ],\n JsonResponse::HTTP_CONFLICT,\n );\n }\n\n /**\n * Remove activity from this user's favorites playlist\n *\n * @param Activity $activity\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function unfavorite(Activity $activity)\n {\n $user = $this->request->user();\n\n $favorites = $activity->favoritedBy($user);\n\n if ($favorites && $favorites->isEmpty()) {\n return $this->response->errorNotFound('Favorite not found.');\n }\n\n $this->authorize('unfavorite', [$activity, $favorites]);\n\n // When you unfavorite an activity,\n // it should remove all the activities in it, including snippets.\n $isDeleted = $favorites->each(function ($favorite) {\n $favorite->forceDelete();\n });\n\n if ($isDeleted) {\n return $this->response->withNoContent();\n }\n\n return $this->response->errorGone('Could not remove favorite.');\n }\n\n /**\n * @param Activity $activity\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function notify(Activity $activity)\n {\n $this->authorize('notify', $activity);\n\n $user = $this->request->user();\n\n $existingNotification = $activity->availabilityNotifications()\n ->where('user_id', $user->id)\n ->exists();\n\n if ($existingNotification) {\n return $this->response->errorWrongArgs('Notification is already configured.');\n }\n\n $notification = Activity\\AvailabilityNotification::create([\n 'user_id' => $user->id,\n 'activity_id' => $activity->id,\n ]);\n\n $this->response\n ->getManager()\n ->setSerializer(new JsonSerializer());\n\n return $this->response->withItem($notification, new AvailabilityNotificationTransformer());\n }\n\n /**\n * @param Activity $activity\n * @param Activity\\AvailabilityNotification $notification\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function unnotify(Activity $activity, Activity\\AvailabilityNotification $notification)\n {\n $this->authorize('unnotify', [$activity, $notification]);\n\n if ($notification->sent_at || $notification->delete()) {\n return $this->response->withNoContent();\n }\n\n return $this->response->errorGone('Could not delete notification.');\n }\n\n public function play(Request $request, Activity $activity)\n {\n $this->authorize('stream', $activity);\n\n $request->validate([\n 'start_time' => 'numeric|between:0,' . $activity->duration,\n ]);\n\n $user = $this->getUserFromRequest($request);\n\n $activity->plays()->create([\n 'user_id' => $user->getId(),\n 'start_time' => $request->input('start_time'),\n ]);\n\n return $this->response->withCreated();\n }\n\n /**\n * @param Activity $activity\n *\n * @return mixed\n */\n public function comment(Activity $activity)\n {\n return $this->newComment($activity);\n }\n\n /**\n * @param Activity $activity\n * @param Comment $comment\n *\n * @return mixed\n */\n public function replyComment(Activity $activity, Comment $comment)\n {\n return $this->newComment($activity, $comment);\n }\n\n /**\n * @param Activity $activity\n * @param Comment|null $comment\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n protected function newComment(Activity $activity, ?Comment $comment = null)\n {\n $this->authorize('comment', [$activity, $comment]);\n\n $this->request->validate([\n 'comment' => 'required|between:1,5000',\n 'type' => 'integer|between:0,3',\n 'visibility' => sprintf('nullable|integer|between:1,%d', count(Comment::getVisibilityLevels())),\n //'start_time' => 'numeric|between:0,'.$activity->duration,\n //'end_time' => 'required_with:start_time|greater_than_or_equal:start_time|numeric|between:0,'.$activity->duration,\n ]);\n\n $threadStartId = null;\n if ($comment) {\n $threadStartId = $comment->thread_start_id ?: $comment->id;\n }\n\n try {\n $newComment = Comment::create([\n 'parent_comment_id' => $comment->id ?? null,\n 'thread_start_id' => $threadStartId,\n 'activity_id' => $activity->id,\n 'user_id' => $this->request->user()->id,\n 'comment' => trim($this->request->input('comment')),\n 'start_time' => $this->request->input('start_time', 0),\n 'end_time' => $this->request->input('end_time', 0),\n 'type' => $this->request->input('type', Comment::TYPE_NEUTRAL),\n 'visibility' => $this->request->input('visibility', Comment::VISIBILITY_PUBLIC),\n ]);\n\n $this->response\n ->getManager()\n ->parseIncludes(['activity'])\n ->setSerializer(new JsonSerializer());\n\n return $this->response->withItem($newComment, new ActivityCommentTransformer());\n } catch (Exception $exception) {\n Sentry::captureException($exception);\n\n return $this->response->errorInternalError('Could not create comment.' . $exception->getMessage());\n }\n }\n\n /**\n * @param Activity $activity\n * @param Comment $comment\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function updateComment(Activity $activity, Comment $comment)\n {\n $this->authorize('comment', [$activity, $comment]);\n\n $this->request->validate([\n 'comment' => 'required|between:1,5000',\n //'start_time' => 'numeric|between:0,'.$activity->duration,\n //'end_time' => 'required_with:start_time|greater_than_or_equal:start_time|numeric|between:0,'.$activity->duration,\n ]);\n\n try {\n $comment->update([\n 'comment' => trim($this->request->input('comment')),\n ]);\n\n $this->response\n ->getManager()\n ->setSerializer(new JsonSerializer());\n\n return $this->response->withOk();\n } catch (Exception $exception) {\n Sentry::captureException($exception);\n\n return $this->response->errorInternalError('Could not update comment.');\n }\n }\n\n public function updateCommentVisibility(Activity $activity, Comment $comment)\n {\n $this->authorize('comment', [$activity, $comment]);\n\n $this->request->validate([\n 'visibility' => sprintf('integer|between:1,%d', count(Comment::getVisibilityLevels())),\n ]);\n\n $visibility = $this->request->input('visibility');\n\n if ($comment->parent !== null) {\n return $this->response->errorWrongArgs('Comment visibility can only be updated on top level comments.');\n }\n\n try {\n $this->activityCommentService->updateCommentVisibility($comment, $visibility);\n\n $this->response\n ->getManager()\n ->setSerializer(new JsonSerializer());\n\n return $this->response->withOk();\n } catch (Exception $exception) {\n Sentry::captureException($exception);\n\n return $this->response->errorInternalError('Could not update comment\\'s visibility.');\n }\n }\n\n /**\n * @param Activity $activity\n * @param Comment $comment\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function deleteComment(Activity $activity, Comment $comment)\n {\n $this->authorize('deleteComment', [$activity, $comment]);\n\n // Delete comment and any children.\n $comment->delete();\n\n return $this->response->withNoContent();\n }\n\n /**\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function fetchComments()\n {\n $user = $this->request->user();\n $this->request->validate([\n 'forUserId' => 'uuid:users,team_id,' . $user->team_id,\n 'types' => 'array',\n 'types.*' => 'integer|between:0,3',\n ]);\n $forUser = null;\n\n $types = [Comment::TYPE_NEUTRAL, Comment::TYPE_GAME_CHANGER, Comment::TYPE_POSITIVE];\n $user = $this->request->user();\n if ($this->request->has('forUserId')) {\n $forUser = $user->team->users()->uuid($this->request->input('forUserId'));\n }\n\n $comments = Comment::query()\n ->whereHas('activity', static function (Builder $builder) use ($user, $forUser): void {\n $builder\n // I left feedback on my own activity; or\n ->where('activities.user_id', $user->getId());\n if ($forUser) {\n // I left feedback on any activity for this user.\n $builder->orWhere([\n 'user_id' => $user->getId(),\n 'activities.user_id' => $forUser->getId(),\n ]);\n }\n })\n ->whereIn('type', $this->request->input('types', $types))\n ->orderBy('created_at', 'desc')\n ->get();\n\n $this->response\n ->getManager()\n ->parseIncludes(['activity', 'user'])\n ->setSerializer(new JsonSerializer());\n\n return $this->response->withCollection($comments, new ActivityCommentTransformer());\n }\n\n public function deleteCoachingFeedback(Activity $activity, CoachingFeedback $coachingFeedback)\n {\n $this->authorize('deleteCoachingFeedback', [$activity, $coachingFeedback]);\n $activity = $coachingFeedback->getActivity();\n\n if ($coachingFeedback->delete()) {\n event(new UpdateSingleEntity(\n entityId: $activity->getId(),\n updateTarget: UpdateTargetEnum::ACTIVITY,\n purpose: 'delete-coaching-feedback',\n ));\n\n return $this->response->withOk();\n }\n\n return $this->response->withError('Delete operation failed. Contact support.', 500);\n }\n\n /**\n * Add new or update Coaching feedback\n *\n * @param Activity $activity\n *\n * @throws AuthorizationException\n * @throws \\Illuminate\\Validation\\ValidationException\n *\n * @return mixed\n */\n public function putCoachingFeedback(Request $request, Activity $activity)\n {\n $user = $request->user();\n\n if (! $user instanceof User) {\n abort(403);\n }\n $teamId = $user->getTeamId();\n\n $this->authorize('coach', $activity);\n\n $this->request->validate([\n 'coach_id' => 'required|uuid:users,team_id,' . $teamId,\n 'coachee_id' => 'required|uuid:users,team_id,' . $teamId,\n 'visibility' => ['required', Rule::in(CoachingFeedback::VISIBILITIES)],\n 'coaching_sections.*.uuid' => 'required|uuid:coaching_sections',\n 'coaching_sections.*.score' => ['required', Rule::in(CoachingSectionFeedback::SCORES)],\n 'coaching_sections.*.summary' => 'string|max:10000',\n 'coaching_sections.*.criteria.*.uuid' => 'required|uuid:coaching_section_criteria',\n 'coaching_sections.*.criteria.*.note' => 'required|string|max:10000',\n 'sharedWithUsers' => [\n 'required_if:visibility,' . CoachingFeedback::VISIBLE_TO_SPECIFIC_USERS,\n 'array',\n ],\n 'sharedWithUsers.*' => [\n 'uuid:users,team_id,' . $teamId,\n ],\n ]);\n\n /** @var User $coach */\n $coach = User::uuid($this->request->input('coach_id'));\n /** @var User $coachee */\n $coachee = User::uuid($this->request->input('coachee_id'));\n $coachingSectionFeedbacks = $this->request->input('coaching_sections');\n\n $previousRecord = $this->coachingFeedbackRepository->getOneForActivityByCoacheeAndCoach(\n $coachee->getId(),\n $coach->getId(),\n $activity->getId()\n );\n $recordIsNew = false;\n if ($previousRecord === null) {\n $recordIsNew = true;\n }\n\n if (! $coachee->isSameTeamId($coach)) {\n return $this->response->errorForbidden('User not member of your team.');\n }\n\n if (! is_array($coachingSectionFeedbacks) || count($coachingSectionFeedbacks) < 1) {\n return $this->response->withError('At least one Coaching Framework Section shall be scored.', 422);\n }\n\n if (! $activity->participants()->where('participants.user_id', $coachee->id)->exists()) {\n return $this->response->withError('Coached user did not participate activity.', 422);\n }\n\n $visibility = $this->request->input('visibility');\n\n $shouldSendNotification = $recordIsNew;\n if ($recordIsNew === false && $visibility !== $previousRecord->getVisibility()) {\n $shouldSendNotification = true;\n }\n\n /**\n * Create CoachingFeedback\n *\n * @var CoachingFeedback $coachingFeedback\n */\n $coachingFeedback = $activity->coachingFeedbacks()->updateOrCreate(\n [\n 'coach_id' => $coach->id,\n 'coachee_id' => $coachee->id,\n ],\n [\n 'framework_id' => $activity->category->id,\n 'visibility' => $visibility,\n ]\n );\n\n $sharedUserIds = [];\n if ($visibility === CoachingFeedback::VISIBLE_TO_SPECIFIC_USERS) {\n foreach ($this->request->input('sharedWithUsers') as $sharedWithUserUuid) {\n /** @var User $user */\n $user = User::uuid($sharedWithUserUuid);\n $sharedUserIds[] = $user->getId();\n }\n }\n\n $syncResult = $coachingFeedback->customAccessUsers()->sync($sharedUserIds);\n\n $scores = [];\n\n\n /**\n * Create CoachingSectionsFeedbacks.\n *\n * @var CoachingSectionFeedback $coachingSectionFeedback\n */\n foreach ($coachingSectionFeedbacks as $coachingSectionFeedbackInput) {\n $coachingSection = CoachingSection::uuid($coachingSectionFeedbackInput['uuid']);\n $coachingSectionFeedback = $coachingFeedback->sectionFeedbacks()->updateOrCreate(\n [\n 'coaching_section_id' => $coachingSection->id,\n ],\n [\n 'score' => array_get($coachingSectionFeedbackInput, 'score'),\n 'summary' => array_get($coachingSectionFeedbackInput, 'summary') ?? '',\n ]\n );\n\n $scores[] = array_get($coachingSectionFeedbackInput, 'score');\n\n $criteria = array_get($coachingSectionFeedbackInput, 'criteria');\n if (is_array($criteria) && ! empty($criteria)) {\n foreach ($criteria as $criteriaFeedbackInput) {\n $coachingSectionFeedback->criterionFeedbacks()->updateOrCreate(\n [\n 'coaching_section_criterion_id' => CoachingSectionCriterion::uuid(array_get($criteriaFeedbackInput, 'uuid'))\n ->id,\n ],\n ['note' => array_get($criteriaFeedbackInput, 'note')],\n );\n }\n }\n }\n\n $coachingFeedback->average_score = array_sum($scores) / count($scores);\n\n if ($recordIsNew === false && $coachingFeedback->getAverageScore() !== $previousRecord->getAverageScore()) {\n $shouldSendNotification = true;\n }\n if (! empty($syncResult['attached']) || ! empty($syncResult['detached']) || ! empty($syncResult['updated'])) {\n $shouldSendNotification = true;\n }\n\n $coachingFeedback->save();\n // ensure updated at for coaching feedback on section feedback summary added.\n $coachingFeedback->touch();\n\n if ($shouldSendNotification) {\n event(new Coached($coachingFeedback));\n }\n\n Datadog::increment('jiminny.activity.score.update', 1, ['company' => $activity->user->team->slug]);\n\n $this->response\n ->getManager()\n ->setSerializer(new JsonSerializer());\n\n $coachingFeedbackTransformer = new CoachingFeedbackTransformer();\n $coachingFeedbackTransformer->setConsumer($this->getUserFromRequest($request));\n\n return $this->response->withItem($coachingFeedback, $coachingFeedbackTransformer);\n }\n\n\n /**\n * Retrieve category criteria for coaching.\n *\n * @param Activity $activity\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function coachingSections(Activity $activity)\n {\n $this->authorize('coach', $activity);\n\n if ($activity->category === null) {\n return $this->response->errorUnprocessable('Category has not yet been assigned.');\n }\n\n $criteria = $activity\n ->category\n ->coachingSections()\n ->where('is_enabled', 1)\n ->orderBy('sequence', 'asc');\n\n $this->response\n ->getManager()\n ->setSerializer(new JsonSerializer());\n\n return $this->response->withCollection($criteria->get(), new CoachingSectionsTransformer());\n }\n\n /**\n * @throws AuthorizationException\n * @throws ValidationException\n *\n * @return mixed\n */\n public function addToPlaylist(Activity $activity, PlaylistTrackFactoryInterface $playlistTrackFactory)\n {\n $this->request->validate([\n 'playlists' => 'required|array',\n 'playlists.*' => 'uuid:playlists',\n 'start_time' => 'numeric|between:0,' . $activity->duration,\n 'end_time' => 'nullable|greater_than_or_equal:start_time|numeric|between:0,' . $activity->duration,\n 'name' => 'required|max:100',\n ]);\n\n $this->authorize('addToPlaylist', [$activity, $this->request->input('playlists')]);\n\n $startTime = $this->request->input('start_time');\n $endTime = $this->request->input('end_time');\n $name = $this->request->input('name');\n /** @var User $user */\n $user = $this->request->user();\n\n // Get playlist by uuid.\n foreach ($this->request->input('playlists') as $playlistId) {\n // Pull out the playlist model.\n $playlist = Playlist::uuid($playlistId);\n\n $playlistTrackFactory->createTrack($playlist, $user, [\n 'name' => $name,\n 'activity' => $activity,\n 'start_time' => $startTime,\n 'end_time' => $endTime,\n ]);\n }\n\n return $this->response->withOk();\n }\n\n public function share(Request $request, Activity $activity): JsonResponse\n {\n $this->authorize('share', $activity);\n\n $request->validate([\n 'note' => 'string|max:1000',\n 'start_time' => 'numeric|between:0,' . $activity->duration,\n 'end_time' => 'nullable|greater_than_or_equal:start_time|numeric|between:0,' . $activity->duration,\n 'recipients.*.type' => 'in:user,group',\n 'recipients.*.id' => 'string|max:40',\n 'share' => 'string|max:255',\n ]);\n\n $user = $request->user();\n\n $recipients = $request->get('recipients');\n $users = $this->userService->convertRecipientsToUsers($user, $recipients);\n\n $shareData = [\n 'from_user_id' => $user->id,\n 'note' => $request->input('note'),\n 'start_time' => $request->input('start_time'),\n 'end_time' => $request->input('end_time'),\n ];\n\n // Create a share object against a notification provider channel\n if ($request->input('share')) {\n /** @var Share $share */\n $share = $activity->shares()->create(\n array_merge(\n $shareData,\n [\n 'notification_provider_channel' => $request->input('share'),\n ]\n )\n );\n\n // All subsequent shares need to reference this row as parent_share_id\n $shareData['parent_share_id'] = $share->id;\n }\n\n // Create a share object against each recipient\n foreach ($users as $recipient) {\n /** @var Share $share */\n $share = $activity->shares()->create(\n array_merge(\n $shareData,\n [\n 'to_user_id' => $recipient->id,\n ]\n )\n );\n\n // If parent_share_id has been selected yet\n if (! isset($shareData['parent_share_id'])) {\n // All subsequent shares need to reference this row as parent_share_id\n $shareData['parent_share_id'] = $share->id;\n }\n }\n\n return $this->response->withOk();\n }\n\n /**\n * @param Activity $activity\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function coachRequest(Activity $activity)\n {\n $this->authorize('coachRequest', $activity);\n\n $this->request->validate([\n 'note' => 'string|max:1000',\n 'start_time' => 'numeric|between:0,' . $activity->duration,\n 'end_time' => 'nullable|greater_than_or_equal:start_time|numeric|between:0,' . $activity->duration,\n 'coachers.*.type' => 'required|in:user',\n 'coachers.*.id' => 'required',\n ]);\n\n $coachers = $this->request->get('coachers');\n $user = $this->request->user();\n $users = $this->userService->convertRecipientsToUsers($user, $coachers);\n\n foreach ($users as $coacher) {\n CoachRequest::create([\n 'user_id' => $coacher->id,\n 'activity_id' => $activity->id,\n 'note' => $this->request->get('note'),\n 'start_time' => $this->request->get('start_time'),\n 'end_time' => $this->request->get('end_time'),\n ]);\n }\n\n return $this->response->withOk();\n }\n\n public function createActivityTopicTriggers(Activity $activity, LoggerInterface $logger): HttpFoundation\\JsonResponse\n {\n $this->authorize('analyzeTopicTriggers', $activity);\n\n if (! $activity->hasTranscription()) {\n return new HttpFoundation\\JsonResponse(\n [\n 'error' => 'Transcription not found.',\n ],\n JsonResponse::HTTP_NOT_FOUND\n );\n }\n\n $logger->info(__METHOD__ . ': queued for analysis', [\n 'activity' => $activity->id_string,\n ]);\n\n dispatch(new ActivityAnalytics\\Job\\AnalyzeActivityTopicTriggers($activity));\n\n return new HttpFoundation\\JsonResponse(null, JsonResponse::HTTP_CREATED);\n }\n\n public function fetchActivityTopicTriggers(\n Activity $activity,\n LoggerInterface $logger,\n ActivityTopicTriggerTransformer $transformer\n ): HttpFoundation\\JsonResponse {\n $this->authorize('fetchTopicTriggers', $activity);\n\n $logger->debug(__METHOD__, [\n 'activity' => $activity->id_string,\n ]);\n\n if (! $activity->isProcessed()) {\n return new HttpFoundation\\JsonResponse([]);\n }\n\n $payload = [];\n\n if ($activity->hasTopicTriggers()) {\n $payload = $activity->getTopicTriggersSorted()\n ->map(\n static fn (Activity\\TopicTrigger $activityTopicTrigger): array\n => $transformer->transform($activityTopicTrigger)\n )\n ->values()\n ->all();\n }\n\n return new HttpFoundation\\JsonResponse($payload);\n }\n\n /**\n * @param Activity $activity\n * @param StatsTransformer $statsTransformer\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function stats(Activity $activity, StatsTransformer $statsTransformer)\n {\n $this->authorize('stream', $activity);\n\n if (! $activity->hasTranscription()) {\n return $this->response->errorNotFound('Waveform data is not yet generated.');\n }\n\n $this->response\n ->getManager()\n ->parseIncludes(['wavedata'])\n ->setSerializer(new JsonSerializer());\n\n return $this->response->withItem($activity, $statsTransformer);\n }\n\n public function destroy(Activity $activity)\n {\n $this->authorize('delete', $activity);\n\n $activity->delete();\n\n \\Log::info('Soft delete activity ' . $activity->id_string . ' by user ' . $this->getUser()->id);\n\n return $this->response->withNoContent();\n }\n\n public function note(Activity $activity)\n {\n $this->authorize('note', $activity);\n\n $this->request->validate([\n 'note' => 'required|min:1|max:2000',\n 'time' => 'required|numeric|min:0|max:86400',\n ]);\n\n $note = $this->request->input('note');\n $time = $this->request->input('time');\n\n $this->activityService->setActivity($activity);\n $this->activityService->takeNote($this->getUser(), $note, $time);\n\n return $this->response->withCreated();\n }\n\n /**\n * Mark an activity as private.\n *\n * @param Activity $activity\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function markAsPrivate(Activity $activity)\n {\n $this->authorize('markAsPrivate', $activity);\n\n if ($activity->is_private === false) {\n $activity->is_private = true;\n $activity->save();\n\n return $this->response->withOk();\n }\n\n return $this->response->withNoContent();\n }\n\n /**\n * Mark an activity as public.\n *\n * @param Activity $activity\n *\n * @throws AuthorizationException\n *\n * @return mixed\n */\n public function markAsPublic(Activity $activity)\n {\n $this->authorize('markAsPublic', $activity);\n\n if ($activity->is_private) {\n $activity->is_private = false;\n $activity->save();\n\n return $this->response->withOk();\n }\n\n return $this->response->withNoContent();\n }\n\n /**\n * @throws LogicException\n */\n public function fetchCloudFrontS3MediaKeys(Activity $activity, PlaybackService $playbackService): JsonResponse\n {\n $masterTrack = $activity->masterTrack()->first();\n\n if (! $masterTrack instanceof Track) {\n throw new LogicException(sprintf('Master track not found for activity \"%s\"', $activity->getUuid()));\n }\n\n return $this->response->withArray(\n $playbackService->generateCookies(\n $masterTrack,\n $this->request->ip(),\n ),\n );\n }\n\n /**\n * @throws ValidationException\n */\n private function updateOrCreateActivitySearch(Request $request, ?Search $search = null): Search\n {\n $request->validate([\n 'name' => 'required|string|min:2|max:100',\n ]);\n\n $user = $this->getUserFromRequest($request);\n\n $searchName = $request->input('name');\n\n if ($search !== null) {\n $search->update([\n 'name' => $searchName,\n ]);\n\n return $search;\n }\n\n $request->validate([\n 'filters' => ['required', 'array', new MultidimensionalArrayMaxCharRule(limit: 255)],\n 'nudges' => 'array|max:' . count(Nudge::MAP_CHANNEL),\n 'nudges.*.channel' => 'required|in:' . implode(',', Nudge::MAP_CHANNEL),\n 'nudges.*.frequency' => 'required|in:' . implode(',', Nudge::MAP_FREQUENCY),\n 'nudges.*.expiresAt' => [\n 'required',\n 'date',\n 'after:today',\n 'before_or_equal:' . now()->addYear()->format('Y-m-d'),\n ],\n ]);\n\n $searchCriteria = Criteria::createFromRequest(\n Collection::make($request->input('filters', []))->all(),\n $user->getTimezone()\n );\n\n $filterSet = $this->activitySearch->getOnDemandPageFilterSet($searchCriteria, $user);\n $this->validateSearch($request, $filterSet, 'filters.');\n\n /** @var Search $search */\n $search = Search::create([\n 'name' => $searchName,\n 'uuid' => Uuid::uuid4()->toString(),\n 'user_id' => $user->getId(),\n ]);\n\n Collection::make($request->input('nudges', []))\n ->each(fn (array $attributes): Nudge => $this->nudgeFactory->createNudge($search, $attributes));\n\n $this->storeNamedSearchFilters(Collection::make($request->all()), $search, $filterSet, 'filters.');\n\n return $search;\n }\n\n private function resolveAccount(\n Team $team,\n Contact $contact,\n ServiceInterface $crmService,\n array $prospects,\n ): ?Account {\n $this->logger->info('Resolving account from contact');\n $account = $contact->getAccount();\n\n if (! $team->hasFeature(FeatureEnum::LINK_ACTIVITY_TO_MULTIPLE_PROSPECTS)) {\n $this->logger->info('Team does not have feature to link activity to multiple prospects');\n\n return $account;\n }\n\n $this->logger->info('Resolving account from prospect data');\n $accountData = array_filter(\n $prospects,\n static fn (array $prospectData): bool => $prospectData['type'] === 'account'\n );\n\n if (! empty($accountData)) {\n $this->logger->info('Found account data in prospects');\n $accountData = reset($accountData);\n\n $account = $team->crm->accounts()->where('crm_provider_id', $accountData['id'])->first();\n\n if (! $account instanceof Account) {\n $this->logger->info('Account not found in database, syncing from CRM');\n $account = $crmService->syncAccount($accountData['id']);\n }\n }\n\n $this->logger->info('Resolved account', ['account' => $account->getId()]);\n\n return $account;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.7124335,"top":0.10055866,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.72140956,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7287234,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"bounds":{"left":0.4481383,"top":0.09736632,"width":0.29288563,"height":0.8818835},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
5019079458621714326
|
-8388112813312469868
|
visual_change
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
43
3
10
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Http\Controllers\API;
use Carbon\Carbon;
use ChaseConey\LaravelDatadogHelper\Datadog;
use Exception;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Rules\In;
use Illuminate\Validation\ValidationException;
use InvalidArgumentException;
use Jiminny\Component\ActivityAnalytics;
use Jiminny\Component\ActivitySearch;
use Jiminny\Component\ActivitySearch\FilterDefinitionCollection;
use Jiminny\Component\PlaybackPage\Comments\Services\ActivityCommentService;
use Jiminny\Component\Queue\Constants;
use Jiminny\Contracts\ES\Events\UpdateSingleEntity;
use Jiminny\Contracts\ES\UpdateTargetEnum;
use Jiminny\Contracts\Nudge\NudgeFactoryInterface;
use Jiminny\Contracts\Playlist\PlaylistTrackFactoryInterface;
use Jiminny\Contracts\Repositories\PlaylistActivityRepository;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Enums\TeamSetting;
use Jiminny\Events\Activities\AiAutomation\ActivityProspectAdded;
use Jiminny\Events\Activities\Coaching\Coached;
use Jiminny\Contracts\Services\Crm\SupportsObjectTypeParseInterface;
use Jiminny\Exceptions\LogicException;
use Jiminny\Exceptions\SocialAccountTokenInvalidException;
use Jiminny\Http\Controllers\API\BaseController as Controller;
use Jiminny\Http\Controllers\CommentContextInterface;
use Jiminny\Http\Responses\Api\AbstractResponse;
use Jiminny\Http\Responses\Api\Response;
use Jiminny\Http\Serializers\JsonSerializer;
use Jiminny\Http\Transformers\ActivityCommentTransformer;
use Jiminny\Http\Transformers\ActivityTopicTriggerTransformer;
use Jiminny\Http\Transformers\ActivityTransformer;
use Jiminny\Http\Transformers\AvailabilityNotificationTransformer;
use Jiminny\Http\Transformers\CoachingFeedbackTransformer;
use Jiminny\Http\Transformers\CoachingSectionsTransformer;
use Jiminny\Http\Transformers\SearchTransformer;
use Jiminny\Http\Transformers\StatsTransformer;
use Jiminny\Jobs\Crm\SaveActivity;
use Jiminny\Jobs\Crm\UpdateStage;
use Jiminny\Jobs\Telephony\StartRecording;
use Jiminny\Jobs\Telephony\StopRecording;
use Jiminny\Jobs\Telephony\ToggleRecording;
use Jiminny\Models\Account;
use Jiminny\Models\Activity;
use Jiminny\Models\Activity\CoachRequest;
use Jiminny\Models\Activity\Comment;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\Activity\Share;
use Jiminny\Models\CoachingFeedback;
use Jiminny\Models\CoachingSection;
use Jiminny\Models\CoachingSectionCriterion;
use Jiminny\Models\CoachingSectionFeedback;
use Jiminny\Models\Contact;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldData;
use Jiminny\Models\Crm\Layout;
use Jiminny\Models\Crm\LayoutEntity;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\LanguageDialect;
use Jiminny\Models\Lead;
use Jiminny\Models\Nudge;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Models\Playlist;
use Jiminny\Models\Stage;
use Jiminny\Models\Team;
use Jiminny\Models\Track;
use Jiminny\Models\User;
use Jiminny\Repositories\CoachingFeedbackRepository;
use Jiminny\Repositories\ElasticActivityRepository;
use Jiminny\Repositories\TeamRepository;
use Jiminny\Rules\CrmReference;
use Jiminny\Rules\MultidimensionalArrayMaxCharRule;
use Jiminny\Services\ActivityService;
use Jiminny\Services\Crm\ProviderRegistry;
use Jiminny\Services\PlaybackService;
use Jiminny\Services\UserService;
use Jiminny\VO\Repository\OnDemandActivitySearch\Criteria;
use Psr\Log\LoggerInterface;
use Ramsey\Uuid\Uuid;
use Sentry;
use Symfony\Component\HttpFoundation;
final class ActivityController extends Controller implements CommentContextInterface
{
// Number of minutes to look back on activities. i.e. a timeout on activity duration.
private const int LOOK_BACK = 180;
public function __construct(
private ProviderRegistry $providerRegistry,
private ActivityService $activityService,
Response $response,
private UserService $userService,
private ActivitySearch\Service\ActivitySearch $activitySearch,
private NudgeFactoryInterface $nudgeFactory,
private ActivityCommentService $activityCommentService,
private LoggerInterface $logger,
private readonly CoachingFeedbackRepository $coachingFeedbackRepository,
private readonly TeamRepository $teamRepository,
) {
parent::__construct($response);
}
public static function getCommentImplementation(): string
{
return Comment::class;
}
public function delete()
{
$this->request->validate([
'*' => 'uuid:activities',
]);
$deletedIds = [];
foreach ($this->request->all() as $activityId) {
$activity = Activity::idOrUuId($activityId);
try {
if ($this->authorize('delete', $activity)) {
$activity->delete();
$deletedIds[] = $activityId;
\Log::info('Soft deleted activity ' . $activity->id_string . ' by user ' . $this->getUser()->id);
}
} catch (AuthorizationException $authorizationException) {
// They didn't have permission.
}
}
return $this->response->withArray($deletedIds);
}
public function update(Request $request, Activity $activity)
{
$this->authorize('updateMetadata', $activity);
$request->validate([
'title' => 'string|max:250',
'category_id' => 'uuid:playbook_categories',
'language' => [
new In(
LanguageDialect::query()
->with('language')
->cursor()
->map(static function (LanguageDialect $languageDialect): string {
return $languageDialect->getLanguageLocale();
})
->all()
),
],
]);
if ($request->has('title')) {
$activity->title = $request->input('title');
}
if ($request->has('category_id')) {
$category = PlaybookCategory::uuid($request->input('category_id'));
if ($category->playbook->team_id !== $request->user()->team_id) {
return $this->response->errorNotFound('Sorry, this category does not belong to your playbook.');
}
$activity->playbook_category_id = $category->id;
}
if ($request->has('language')) {
if (! $activity->isInProgress()) {
return $this->response->withError(
'Activity language can only be set while the meeting is in progress.',
400
);
}
$activity->setLanguageCode($request->input('language'));
}
$activity->save();
return $this->response->withOk();
}
// XXX: This should be merged with the update method.
/**
* @param Activity $activity
*
* @throws AuthorizationException
* @throws SocialAccountTokenInvalidException
*
* @return mixed
*/
public function summarize(Activity $activity): mixed
{
$this->logger->info('[Log Activity] Summarizing activity ', [
'activityId' => $activity->getUuid(),
'payload' => $this->request->all(),
]);
$this->authorize('update', $activity);
$this->logger->info('[Log Activity] Validating summary');
// Validate the payload.
$this->validateSummary($activity);
// All objects must belong to this team.
/** @var User $user */
$user = $this->request->user();
$team = $user->getTeam();
$crmService = $this->providerRegistry->get($team->crm->provider);
try {
$crmUser = $user;
if ($user->isCrmRequired() === false) {
$crmUser = $team->owner;
}
$crmService->setUser($crmUser);
} catch (SocialAccountTokenInvalidException $accountTokenInvalidException) {
// Return a JSON response with the response array and status code.
return $this->response->errorWrongArgs($accountTokenInvalidException->getMessage());
}
$rawEntities = $this->request->input('entities');
/** @var Layout $layout */
$layout = $team->crm->layouts()->uuid(
$this->request->input('layout_id')
);
// Delay execution of CRM jobs to avoid locking issues.
$jobDelay = 0;
// If we have arrived from a notification, mark it as read.
$notificationId = $this->request->input('nId');
if ($notificationId) {
$notification = $user->unreadNotifications->where('id', $notificationId)->first();
if ($notification) {
$notification->markAsRead();
}
}
$title = $this->request->input('title');
$prospects = $this->request->input('prospects');
$opportunityId = $this->request->input('opportunity_id');
$stageId = $this->request->input('stage_id');
$categoryId = $this->request->input('category_id');
$summary = $this->request->input('summary');
$crmProviderId = $this->request->input('crm_id');
$isInternal = $this->request->input('is_internal') ?? false;
$lead = null;
$category = null;
$account = null;
$contact = null;
$opportunity = null;
$stage = null;
$callStage = null;
foreach ($prospects as $prospectData) {
$objectId = $prospectData['id'];
if ($objectId === null) {
continue;
}
$objectType = $prospectData['type'];
$this->logger->info('debug', ['prospect_data' => $prospectData]);
try {
if ($objectType === null) {
$this->logger->info('no object type');
if ($crmService instanceof SupportsObjectTypeParseInterface) {
$objectType = $crmService->parseObjectType($objectId);
}
}
switch ($objectType) {
case 'lead':
$this->logger->info('Processing lead');
/** @var Lead|null $lead */
$lead = $team->crm->leads()->where('crm_provider_id', $objectId)->first();
// Lead does not exist locally, import it.
if ($lead === null) {
$this->logger->info('Lead does not exist locally');
/** @var Lead $lead */
$lead = $crmService->syncLead($objectId);
}
$this->logger->info('Lead found', ['leadId' => $lead->id]);
$activity->lead_id = $lead->id;
if ($stageId === null) {
$this->logger->info('Stage ID is null');
// If it was not provided, just assume it is the current stage.
$callStage = $lead->stage;
break;
}
$this->logger->info('Looking for stage');
// Determine if they have changed the stage.
/** @var Stage $stage */
$stage = $team->crm->stages()
->uuid($stageId, false)
->where('type', Stage::TYPE_LEAD)
->firstOrFail();
$this->logger->info('Stage found', ['stageId' => $stage->id, 'lead_stage' => $lead->stage_id]);
if ($lead->stage_id && $lead->stage_id !== $stage->id) {
$this->logger->info('Stage has changed');
// Storage current stage on activity.
$callStage = $lead->stage;
// The stage has changed, update in remote CRM.
dispatch(new UpdateStage($activity, $lead, $callStage, $stage));
$this->logger->info(
sprintf(
'[%s] User changing lead stage from %s to %s',
$crmService->getDisplayName(),
$callStage->getName(),
$stage->getName()
),
[
'user' => $user->getUuid(),
'lead' => $lead->getUuid(),
]
);
} else {
$this->logger->info('Stage has not changed');
// Stage remains as current.
$callStage = $stage;
}
break;
case 'account':
$this->logger->info('Processing account');
// If the object is not a lead, it should be an account.
$account = $team->crm->accounts()->where('crm_provider_id', $objectId)->first();
// Account does not exist locally, import it.
if ($account === null) {
$this->logger->info('Account does not exist locally');
$account = $crmService->syncAccount($objectId);
}
$this->logger->info('Account found', ['accountId' => $account->id]);
break;
case 'contact':
$this->logger->info('processing contact');
$contact = $team->crm->contacts()->where('crm_provider_id', $objectId)->first();
// Contact does not exist locally, import it.
if (! $contact instanceof Contact) {
$this->logger->info('contact does not exist locally');
$contact = $crmService->syncContact($objectId);
}
$this->logger->info('resolving account');
$account = $this->resolveAccount($team, $contact, $crmService, $prospects);
break;
}
// If they have specified an opportunity, retrieve this with stage.
if ($opportunityId) {
$this->logger->info('opportunity id is set');
$opportunity = $team->crm->opportunities()->where('crm_provider_id', $opportunityId)->first();
// Opportunity does not exist locally, import it.
if ($opportunity === null) {
$this->logger->info('opportunity does not exist locally');
$opportunity = $crmService->syncOpportunity($opportunityId);
}
if ($stageId === null) {
$this->logger->info('stage id is null');
// If it was not provided, just assume it is the current stage.
$callStage = $opportunity->stage ?? null;
} else {
$this->logger->info('looking for stage');
/** @var ?Stage $opportunityStage */
$opportunityStage = $team->crm
->stages()
->uuid($stageId, false)
->where('type', Stage::TYPE_OPPORTUNITY)
->first();
// There is a chance we still cannot import this opportunity.
if ($opportunityStage !== null && $opportunity !== null && $opportunity->stage_id !== $opportunityStage->id) {
$this->logger->info('opportunity stage has changed');
// Storage current stage on activity.
$callStage = $opportunity->stage;
dispatch(new UpdateStage($activity, $opportunity, $callStage, $opportunityStage));
$this->logger->info(
sprintf(
'[%s] User changing opportunity stage from %s to %s',
$crmService->getDisplayName(),
$callStage->name,
$opportunityStage->name
),
[
'userId' => $user->id_string,
'opportunityId' => $opportunity->id_string,
]
);
} else {
$this->logger->info('opportunity stage has not changed');
// Stage remains as current.
$callStage = $opportunityStage;
}
}
}
if ($crmProviderId) {
// Cast $crmProviderId to string otherwise it won't use database index for some records
$linkedActivity = Activity::where('crm_provider_id', (string) $crmProviderId)->first();
// Check if this activity has already been assigned to a different activity.
if ($linkedActivity && $linkedActivity->id !== $activity->id) {
throw new InvalidArgumentException(
'Sorry, the linked task has already been logged under a different call. '
. 'Please choose another linked task.'
);
}
}
} catch (InvalidArgumentException $exception) {
$this->logger->error('Failed to process prospect', [
'prospect_data' => $prospectData,
'reason' => $exception->getMessage(),
]);
// Return a JSON response with the response array and status code.
return $this->response->errorWrongArgs($exception->getMessage());
} catch (Exception $exception) {
$this->logger->error('Failed to process prospect', [
'prospect_data' => $prospectData,
'reason' => $exception->getMessage(),
]);
// Return a JSON response with the response array and status code.
return $this->response->errorInternalError(
'Sorry, an error occurred. Please try again or reach out to support if the problem continues.'
);
}
}
if ($categoryId) {
$category = PlaybookCategory::uuid($categoryId);
if ($category->playbook->team_id !== $team->id) {
throw new InvalidArgumentException('Sorry, this category does not belong to your playbook.');
}
$activity->playbook_category_id = $category->id;
}
$this->logger->info('Prospect data', [
'lead_id' => $lead?->getId(),
'account_id' => $account?->getId(),
'contact_id' => $contact?->getId(),
'opportunity_id' => $opportunity?->getId(),
'stage_id' => $stage?->getId(),
]);
if ($title) {
$activity->title = $title;
}
if ($summary) {
$activity->summary = $summary;
}
if ($crmProviderId) {
$activity->crm_provider_id = $crmProviderId;
}
if ($callStage) {
$this->logger->info('Setting stage id', ['stageId' => $callStage->id]);
$activity->stage_id = $callStage->id;
}
if ($lead) {
$this->logger->info('Setting lead id', ['leadId' => $lead->id]);
$activity->lead_id = $lead->id;
// If we are changed from an account > lead, unset the account data.
$this->logger->info('Unsetting account id, opportunity id, contact id, value');
$activity->account_id = null;
$activity->opportunity_id = null;
$activity->contact_id = null;
$activity->value = null;
}
if ($account) {
$this->logger->info('Setting account id', ['accountId' => $account->id]);
$activity->account_id = $account->id;
// If we are changed from an lead > account, unset the lead data.
$this->logger->info('unsetting lead id');
$activity->lead_id = null;
// Unset the contact if switching different accounts. Will be set up below if still applicable.
if (! $team->hasFeature(FeatureEnum::LINK_ACTIVITY_TO_MULTIPLE_PROSPECTS) || empty($contact)) {
$this->logger->info('Unsetting contact id');
$activity->contact_id = null;
}
}
if ($opportunity) {
$this->logger->info('setting opportunity id', ['opportunityId' => $opportunity->id]);
$this->logger->info('unsetting lead id');
$activity->opportunity_id = $opportunity->id;
$activity->value = $opportunity->value;
// If we are changed from an lead > account, unset the lead data.
$activity->lead_id = null;
}
if ($contact) {
$this->logger->info('setting contact id', ['contactId' => $contact->id]);
$activity->contact_id = $contact->id;
// If we are changed from an lead > account, unset the lead data.
$this->logger->info('Unsetting lead id');
$activity->lead_id = null;
}
$activity->is_internal = $isInternal;
$activity->save();
$activity->refresh();
$this->logger->notice('Activity saved', [
'activity_id' => $activity->getId(),
'lead_id' => $activity->lead_id,
'account_id' => $activity->account_id,
'contact_id' => $activity->contact_id,
'opportunity_id' => $activity->opportunity_id,
'stage_id' => $activity->stage_id,
'crm_provider_id' => $activity->getCrmProviderId(),
]);
// Store entities as field data on the activity.
$updatedData = $this->storeEntities($crmService, $activity, $layout, $rawEntities);
if ($activity->isLoggable()) {
// Follow-up Task or Event data.
$followupData = $this->fetchFollowupEntities($crmService, $layout, $rawEntities);
$this->logger->info('CRM LOG manual log triggered', [
'activityId' => $activity->getUuid(),
'followupData' => $followupData,
'userId' => $user->getUuid(),
]);
// Store data in the CRM.
// ++add check for crm_required
$job = new SaveActivity($activity, $followupData);
if ($updatedData) {
$job->delay(Carbon::now()->addMinutes($jobDelay));
}
dispatch($job);
// Manually dispatch log for Opportunity or Prospect added
if ($activity->hasOpportunity() || $activity->hasProspect()) {
event(new ActivityProspectAdded(
activity: $activity,
eventSource: 'manually-log-crm-data'
));
}
}
return $this->response->withOk();
}
/**
* Extract any activity data to be upserted in the Lead/Opportunity/Task etc in the CRM.
*
* @param ServiceInterface $service
* @param Activity $activity
* @param Layout $layout
* @param array $entities The raw entity data from user
*
* @return array
*/
private function storeEntities(ServiceInterface $service, Activity $activity, Layout $layout, array $entities): array
{
$updatedData = [];
$existingData = $activity->data()->get();
// We need to delete any existing data to overwrite with latest values.
$activity->data()->delete();
$layoutEntities = $layout->entities()
->with('field', 'parent')
->whereHas('field', function ($query) {
$query->where('is_selectable', 1);
})
->get();
/** @var LayoutEntity $entity */
foreach ($layoutEntities as $entity) {
// If the user has provided a value for this entity
if (array_key_exists($entity->id_string, $entities)) {
$value = $entities[$entity->id_string];
// Convert raw data into values that the CRM can consume.
if ($value) {
$value = $service->normalizeValue($entity->field->type, $value);
}
// Check the field is part of the activity-summary section.
if ($entity->parent && $entity->parent->label === 'activity-summary' && $value) {
// This is the internal database ID, not the external CRM ID.
$objectId = null;
switch ($entity->field->object_type) {
case Field::OBJECT_ACCOUNT:
$objectId = $activity->account_id;
break;
case Field::OBJECT_CONTACT:
$objectId = $activity->contact_id;
break;
case Field::OBJECT_OPPORTUNITY:
$objectId = $activity->opportunity_id;
break;
case Field::OBJECT_LEAD:
$objectId = $activity->lead_id;
break;
case Field::OBJECT_TASK:
case Field::OBJECT_EVENT:
$objectId = $activity->id;
break;
}
if ($objectId) {
/** @var FieldData $data */
$data = $activity->data()->create([
'crm_layout_entity_id' => $entity->id,
'crm_field_id' => $entity->crm_field_id,
'object_type' => $entity->field->object_type,
'object_id' => $objectId,
'value' => $value,
]);
// Never send read-only field data to the CRM.
if ($entity->read_only === false && $entity->is_visible) {
$existingValue = $existingData
->where('crm_layout_entity_id', $entity->id)
->where('crm_field_id', $entity->crm_field_id)
->where('object_type', $entity->field->object_type)
->where('object_id', $objectId)
->first();
// If the field was actually changed, we need to reflect this in the CRM too.
if ($existingValue === null || $existingValue->value !== $value) {
$updatedData[] = $data->id;
}
}
}
}
}
}
return $updatedData;
}
/**
* Extract any followup data to be dispatched in a job to create a new Task/Event in the CRM.
*
* @param ServiceInterface $crmService
* @param Layout $layout
* @param array $entities The raw entity data from user
*
* @return array
*/
private function fetchFollowupEntities(ServiceInterface $crmService, Layout $layout, array $entities): array
{
$fieldData = [];
foreach ($entities as $entityId => $value) {
// Only bother with fields that have a value.
if ($value) {
// Extract the entity from the UUID. Check the field is valid and part of the follow-up section.
$entity = $layout->entities()
->uuid($entityId, false)
->whereHas('parent', function ($query) {
$query->where('label', 'follow-up');
})
->whereHas('field', function ($query) {
$query->where('is_selectable', 1);
})
->first();
if ($entity) {
// Convert raw data into values that the CRM can consume.
$value = $crmService->normalizeValue($entity->field->type, $value);
// Add the field and value to the payload.
$fieldData += [
$entity->field->crm_provider_id => $value,
];
}
}
}
return $fieldData;
}
/**
* @param Activity $activity
*/
private function validateSummary(Activity $activity): void
{
$team = $activity->user->team;
$crmProvider = $team->crm->provider;
$attributes = [];
$rules = [
'layout_id' => 'required|uuid:crm_layouts,crm_configuration_id,' . $team->crm_id,
'title' => 'string|max:250',
'prospects' => 'required|array',
'opportunity_id' => new CrmReference($crmProvider),
'category_id' => 'uuid:playbook_categories|required_unless:is_internal,true',
'stage_id' => 'uuid:stages,team_id,' . $team->id, // Todo: move to proper validator
'summary' => 'max:50000',
'nId' => 'exists:notifications,id',
'crm_id' => new CrmReference($crmProvider),
'entities' => 'array',
'is_internal' => 'boolean',
];
/** @var Layout $layout */
$layout = $team->crm->layouts()->uuid($this->request->input('layout_id'));
// Only validate fields, not headers etc. If not loggable, we don't care about follow-up section.
$entities = $layout->entities()
->where('read_only', 0)
->whereHas('field', function ($query) {
$query->where('is_selectable', 1);
})
->whereHas('parent', function ($query) use ($activity) {
if ($activity->isLoggable() === false) {
$query->where('label', '<>', 'follow-up');
}
});
$isInternal = $this->request->input('is_internal', false);
foreach ($entities->get() as $entity) {
$rules += $this->buildFieldValidator($entity, $isInternal);
$attributes += $this->buildFieldMessage($entity);
}
$this->request->validate($rules, [], $attributes);
}
private function buildFieldValidator(LayoutEntity $entity, bool $isInternal): array
{
return [
'entities.' . $entity->id_string => $entity->getValidator($isInternal),
];
}
/**
* @param LayoutEntity $entity
*
* @return array
*/
private function buildFieldMessage(LayoutEntity $entity): array
{
$label = $entity->label;
if ($label === null) {
$label = $entity->field->label;
}
return [
'entities.' . $entity->id_string => $label,
];
}
public function search(Request $request, ElasticActivityRepository $repository): JsonResponse
{
/** @var User $user */
$user = $request->user();
$this->debugLog(
$user,
'User extracted from request',
['user' => $user->getId(), 'tz' => $user->getTimezone()]
);
$searchCriteria = Criteria::createFromRequest($request->all(), $user->getTimezone());
$this->debugLog(
$user,
'ActivitySearch criteria built',
['searchCriteria' => $searchCriteria]
);
$filterSet = $this->activitySearch->getHomepageFilterSet($searchCriteria, $user);
$this->debugLog($user, 'FilterSet built', ['filterSet' => $filterSet]);
$this->validateSearch($request, $filterSet);
$this->debugLog($user, 'Request validated');
$searchResponse = $repository->onDemandSearch($user, $searchCriteria, $filterSet);
/** @var Collection<Activity> $activities */
$activities = $searchResponse['results'];
$this->debugLog($user, 'Activities ES response extracted');
$hideInternalMeetingsSetting = $this->teamRepository->getTeamSettingByTeamId(
$user->getTeamId(),
TeamSetting::HIDE_INTERNAL_SCHEDULED_MEETINGS->name(),
);
if ($hideInternalMeetingsSetting?->getValue() === '1') {
$activities = $activities->filter(function (Activity $activity) {
if ($activity->is_internal && empty($activity->actual_start_time)) {
return false;
}
return true;
});
}
$this->debugLog($user, 'Internal meetings (?!) filtered');
$this->response->getManager()
->parseIncludes([
'category',
'organizer.group',
'prospect',
'stage',
'opportunity',
'stats',
'scorecards',
'masterTrack',
'activeParticipants',
'notification',
])
->setSerializer(new JsonSerializer());
$transformerExcludes = $this->request->input('exclude');
if ($transformerExcludes) {
$this->response->getManager()->parseExcludes($transformerExcludes);
}
$this->debugLog($user, 'Response Manager (?!) applied');
$transformer = new ActivityTransformer();
$transformer->setConsumer($user);
$this->debugLog($user, 'Activity Transformer added');
$resource = new \League\Fractal\Resource\Collection($activities, $transformer);
$page = $searchCriteria->getPageNumber();
$this->debugLog($user, 'Search criteria page number called', ['page' => $page]);
$histogram = array_pluck(array_get($searchResponse, 'histogram.buckets', []), 'doc_count', 'key_as_string');
$this->debugLog($user, 'Histogram generated. Response is ready.', ['histogram' => $histogram]);
return $this->response->withArray([
'pagination' => [
'total' => $searchResponse['totalHits'],
'current' => $page,
'prev' => max($page - 1, 1),
'next' => $page + 1,
],
'results' => $this->response->getManager()->createData($resource)->toArray(),
'histogram' => $histogram,
]);
}
private function debugLog(User $user, string $logMessage, ?array $context = []): void
{
// Debug for Learning People Only
if ($user->getTeamId() !== 260) {
return;
}
Log::notice(
sprintf('[activity-search-controller] %s', $logMessage),
$context
);
}
/** @throws ValidationException */
private function validateSearch(Request $request, FilterDefinitionCollection $filterSet, ?string $prefix = null): void
{
$rules = [
'exclude' => 'array',
'limit' => 'integer|min:1|max:50',
'page' => 'integer|min:1',
];
if ($prefix !== null && mb_strpos($prefix, '.') !== false) {
$rules[rtrim($prefix, '.')] = sprintf(
'required|array|max:%d',
$filterSet->count()
);
}
$validationRules = $filterSet->getValidationRules($prefix)
->merge($rules)
->all();
$request->validate($validationRules);
}
public function createActivitySearch(Request $request, SearchTransformer $searchTransformer): JsonResponse
{
/** @var User $user */
$user = $request->user();
$search = $this->updateOrCreateActivitySearch($request);
$this->response
->getManager()
->setSerializer(new JsonSerializer());
return $this->response->withItem(
$search,
$searchTransformer
->withConsumer($user)
);
}
public function updateActivitySearch(Request $request, Search $search): JsonResponse
{
$this->authorize('update', $search);
$this->updateOrCreateActivitySearch($request, $search);
return $this->response->withOk();
}
private function storeNamedSearchFilters(
Collection $request,
Search $search,
FilterDefinitionCollection $filterSet,
?string $prefix = null,
): self {
$arrayTypeProperties = $filterSet
->getPropertyTypes([
FilterDefinitionCollection::PROPERTY_TYPE_ARRAY,
])
->all();
$supportedRequestProperties = $filterSet->getSupportedRequestProperties($prefix);
foreach ($supportedRequestProperties as $requestPropertyName) {
if (! array_has($request, $requestPropertyName)) {
continue;
}
/** @var string|string[] $propertyValue */
$propertyValue = array_get($request, $requestPropertyName);
$propertyName = $prefix === null
? $requestPropertyName
: mb_substr($requestPropertyName, mb_strlen($prefix));
$isArrayType = array_has($arrayTypeProperties, $propertyName);
if (! $isArrayType) {
/** @var string $requestPropertyValue */
$search->filters()->updateOrCreate(
[
'filter' => $propertyName,
],
[
'value' => $propertyValue,
]
);
continue;
}
/** @var string[] $requestPropertyValue */
/** @var SearchFilter[]|Collection $existingFilterValues */
$existingFilterValuesKeyed = $search->filters()
->where('filter', $propertyName)
->get()
->keyBy('id');
// Iterate over values provided as request parameters
foreach ($propertyValue as $value) {
/** @var SearchFilter|null $valueFilter */
$valueFilter = $search->filters()
->where(
[
'filter' => $propertyName,
'value' => $value,
]
)
->first();
if ($valueFilter !== null) {
// Remove filter value pair from list to be deleted
$existingFilterValuesKeyed->forget($valueFilter->id);
} else {
// Add new filter/value pair
$search->filters()->updateOrCreate([
'filter' => $propertyName,
'value' => $value,
]);
}
}
// Delete filter value pairs for this filter that no longer exist in request parameters
foreach ($existingFilterValuesKeyed as $existingFilter) {
$existingFilter->delete();
}
}
/** @var Collection<int, SearchFilter> $filtersKeyed */
$filtersKeyed = $search->filters()->get()->keyBy('filter');
// wipe removed filters from this search
foreach ($filtersKeyed as $filterName => $filter) {
if (array_has($request, $prefix . $filterName)) {
continue;
}
// Remove all filter values for this filter
$search->filters()->where('filter', $filterName)->delete();
}
return $this;
}
/**
* @throws AuthorizationException
*/
public function fetchActivitySearch(
Search $search,
Request $request,
SearchTransformer $searchTransformer,
): JsonResponse {
$this->authorize('view', $search);
/** @var User $user */
$user = $request->user();
$this->response
->getManager()
->setSerializer(new JsonSerializer());
return $this->response->withItem(
$search,
$searchTransformer
->withConsumer($user)
);
}
public function listActivitySearch(Request $request, SearchTransformer $searchTransformer): JsonResponse
{
/** @var User $user */
$user = $request->user();
$this->response
->getManager()
->setSerializer(new JsonSerializer());
return $this->response->withCollection(
$user->searches()->get(),
$searchTransformer
->withConsumer($user)
);
}
/**
* Deletes a saved search
*
* @param Request $request
* @param Search $search
*
* @throws Exception
*
* @return JsonResponse
*/
public function deleteActivitySearch(Request $request, Search $search): JsonResponse
{
$this->authorize('delete', $search);
// Disable and orphan any AutomatedReports that use this search
$search->automatedReports()->withTrashed()->update([
'activity_search_id' => null,
'status' => false,
]);
// Delete filters and the search itself
$search->filters()->delete();
$search->delete();
return $this->response->withOk();
}
public function live(Request $request, ElasticActivityRepository $repository): JsonResponse
{
$user = $this->getUserFromRequest($request);
$this->request->validate([
'sort_direction' => 'in:asc,desc',
'limit' => 'integer|min:1|max:50',
'page' => 'integer|min:1',
]);
$activities = $repository->getLiveCoachingEligibleActivities(
user: $user,
lookBackMinutes: self::LOOK_BACK,
limit: (int) $this->request->input('limit', 25),
page: (int) $this->request->input('page', 1),
sortBy: ['actual_start_time', 'scheduled_start_time'],
sortDirection: (string) $this->request->input('sort_direction', 'asc'),
);
$this->response
->getManager()
->parseIncludes(['organizer.group', 'prospect'])
->setSerializer(new JsonSerializer());
return $this->response->withCollection($activities, new ActivityTransformer());
}
/**
* @param Activity $activity
*
* @throws AuthorizationException
*
* @return mixed
*/
public function show(Activity $activity, ActivityService $activityService): JsonResponse
{
$this->authorize('show', $activity);
$user = $activity->getUser();
$team = $user->getTeam();
// Sync the opportunity with the latest data if possible.
if ($activity->opportunity_id) {
try {
$crmService = $this->providerRegistry->get($team->crm->provider);
if (! $user->isCrmRequired()) {
$crmService->setUser($team->getOwner());
} else {
$crmService->setUser($user);
}
$crmService->syncOpportunity($activity->opportunity->crm_provider_id);
} catch (Exception $exception) {
// Move on.
}
}
$activityData = $activityService->getActivityData($this->request->user(), $activity);
return response()->json($activityData);
}
public function createRecording(Activity $activity)
{
$this->authorize('record', $activity);
if ($activity->hasRecordingReasonComplianceRestricted()) {
return $this->response->errorGone('Recording this number has been disabled by your organization.');
}
// Tell Twilio to start recording this activity.
if ($activity->recording_state === Activity::RECORDING_OFF) {
$job = (new StartRecording($activity))->onQueue(Constants::QUEUE_CONFERENCES);
dispatch($job);
return $this->response->withCreated();
}
return $this->response->errorGone('Activity is already recording.');
}
public function updateRecording(Request $request, Activity $activity)
{
$this->authorize('record', $activity);
$request->validate([
'preference' => 'boolean',
'state' => [
'string',
Rule::in([
Activity::RECORDING_IN_PROGRESS,
Activity::RECORDING_PAUSED,
]),
],
]);
if ($request->has('state')) {
if ($activity->hasRecordingReasonComplianceRestricted()) {
return $this->response->errorGone('Recording this number has been disabled by your organization.');
}
// Toggle the recording state between paused and resumed.
if (! $activity->isRecordingState(Activity::RECORDING_OFF)) {
$job = (new ToggleRecording($activity, $request->input('state')))
->onQueue(Constants::QUEUE_CONFERENCES);
dispatch($job);
return $this->response->withOk();
}
return $this->response->errorGone('Recording is not toggleable.');
}
if ($request->has('preference')) {
$activity->update([
'recording_preference' => $request->input('preference') ? 1 : 0,
]);
return $this->response->withOk();
}
return $this->response->errorWrongArgs('Something went wrong');
}
public function stopRecording(Activity $activity)
{
$this->authorize('stopRecord', $activity);
// Tell Twilio to stop recording this activity.
if ($activity->isRecordingState(Activity::RECORDING_IN_PROGRESS)) {
$job = (new StopRecording($activity))->onQueue(Constants::QUEUE_CONFERENCES);
dispatch($job);
return $this->response->withOk();
}
return $this->response->errorGone('Activity is not recording.');
}
/**
* Add activity to this user's favorites playlist
*
* @throws AuthorizationException
*/
public function favorite(Activity $activity, PlaylistActivityRepository $playlistActivityRepository): JsonResponse
{
$this->authorize('favorite', $activity);
$user = $this->getUserFromRequest($this->request);
$favorite = $activity->wasFavoritedBy($user);
$name = $activity->activity_title ?? '';
// It needs to check at least one record.
if (! $favorite) {
$favoritePlaylist = $user->favoritePlaylist();
$playlistActivity = $playlistActivityRepository->findByBaseActivityUserAndPlaylist(
$activity,
$user,
$favoritePlaylist
);
if ($playlistActivity !== null) {
$playlistActivity->update(
// Just update, don't sort.
['start_time' => 0, 'name' => mb_strimwidth($name, 0, 100)],
);
} else {
$playlistActivity = $activity->playlistActivities()->create([
'playlist_id' => $favoritePlaylist->getId(),
'user_id' => $user->getId(),
'start_time' => 0,
'name' => mb_strimwidth($name, 0, 100),
]);
// Sort it on top.
$playlistActivity->update(
[
'sort' => $playlistActivityRepository->calculateNewSortOrder(
null,
$playlistActivity,
),
],
);
}
$playlistActivityRepository->calculateNewSortOrder(null, $playlistActivity);
return new JsonResponse([], JsonResponse::HTTP_CREATED);
}
return new JsonResponse(
[
'error' => [
'code' => AbstractResponse::CODE_CONFLICT,
'http_code' => JsonResponse::HTTP_CONFLICT,
'message' => 'Resource Already Exists',
],
],
JsonResponse::HTTP_CONFLICT,
);
}
/**
* Remove activity from this user's favorites playlist
*
* @param Activity $activity
*
* @throws AuthorizationException
*
* @r...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
56854
|
1978
|
1
|
2026-05-19T08:33:43.197052+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179623197_m1.jpg...
|
PhpStorm
|
faVsco.js – SearchTransformer.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpAPPDOCKER• ₴1D SlackFileEditViewGoHistoryWindowHelpAPPDOCKER• ₴1DEV (-zsh)₴82app/Jobs/Crm/MatchActivityCrmData.phpapp/Jobs/Middleware/HandleHubspotRateLimit.phpAPP (-zst47++++++p42++++++*app/Mcp/Servers/JiminnyServer.phpapp/Mcp/Tools/GetMeTool.php157++++++•app/Models/Feature/FeatureEnum.phpapp/Services/Activity/HubSpot/ProviderResolver.php+-app/Services/Activity/HubSpot/ProviderResolverInterface.phpapp/Services/Activity/HubSpot/Providers/Provider.phpapp/Services/Activity/HubSpot/Providers/ProviderKixie.php+-app/Services/Activity/HubSpot/Providers/Provider0rum.phpapp/Services/Activity/HubSpot/Providers/ProviderTwilio.phpapp/Services/Activity/HubSpot/Providers/ProviderTwilioFlex.phpapp/Services/Activity/HubSpot/Service.phpapp/Services/Crm/Hubspot/Client.phpapp/Services/Crm/Hubspot/HubspotClientInterface.phpapp/Services/Crm/Hubspot/Pagination/HubspotPaginationService.phpapp/Services/Crm/Hubspot/Pagination/PaginationState.phpdatabase/migrations/2026_05_13_124153_create_mcp_feature_flag.phptests/Feature/Mcp/GetMeToolFeatureTest.phptests/Feature/Mcp/ListCallsToolFeatureTest.phptests/Feature/Mcp/McpTestHelpersTrait.phptests/Unit/Component/ES/ChunkSizeTest.phptests/Unit/Component/ES/Processor/DT0s/SelectionListTest.phptests/Unit/Component/ES/Processor/TargetEntitiesSelectorTest.phptests/Unit/Component/MeetingBot/Service/ParticipantMatcherTest.phptests/Unit/Exceptions/RateLimitExceptionTest.phptests/Unit/Jobs/Crm/MatchActivityCrmDataTest.phptests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.phptests/Unit/Services/Activity/HubSpot/ServiceTest.phptests/Unit/Services/Crm/Hubspot/ClientTest.phptests/Unit/Services/Crm/Hubspot/Pagination/HubspotPaginationServiceTest.php97++++++-132++++++•15++++++21++++--2+-25++++++.140++++++•2+-19++++++50++++++-27++++++-39++++++-6856++++++-+-151++++++-109++++++-250++++++-283++++++=37 files changed, 1587 insertions(+), 344 deletions(-)create mode 100644 app/Component/ES/ChunkSize.phpcreate mode 100644 app/Jobs/Middleware/HandleHubspotRateLimit.phpcreate mode 100644 app/Mcp/Tools/GetMeTool.phpcreate mode 100644 database/migrations/2026_05_13_124153_create_mcp_feature_flag.phpcreate mode 100644 tests/Feature/Mcp/GetMeToolFeatureTest.phpcreate mode 100644 tests/Unit/Component/ES/ChunkSizeTest.phpcreate mode 100644 tests/Unit/Exceptions/RateLimitExceptionTest.phpcreate mode 100644 tests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.phplukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (master) $ git pullAlready up to date.lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (master) $ co -b JY-20676-delete-reSwitched to a new branch 'JY-20676-delete-report-related-objects'lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20676-delete-report-related-obHomeDMsActivityFilesLaterMore> 0EDJiminny ...# Jiminny-Dg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...• Direct messages€. Vasil Vasilev8. Nikolay Yankov%. Galya Dimitrova. Aneliya Angelovaão Stefka Stoyanova. Stoyan Tomovd Todor Stamatov "Kd. Mario GeorgievNikolay Ivanovd. James Graham2 Stoyan TanevRo Steliyan GeorgievLukas Kovalik y... OAppsJira CloudToastSupport Daily • in 3 h 27 m100% <73• Tue 19 May 11:33:42Describe what you are looking forNikolay Yankov6 0MessagesAdd canvasO Files+Nikolay YankovYesterday ~имаше ли нещь . y-..-Lukas Kovalik 2:28 PMтрябва да си вързан към SF да работиNikolay Yankov 2:28 PMaxaaaNikolay Yankov 2:41 PMимаме approve на PRда го даваме за QA?Lukas Kovalik 2:42 PMдаNikolay Yankov 3:02 PMтестове фейлватрьннах го 2 пътиToday ~Nikolay Yankov 10:05 AM/api/v2/user/ask-anything-prompts?target=on_demandhas_reports/api/v2/user/ask-anything-prompts/3381a35f-f1a3-431d-9510-bd079cd80ed6DELETE/api/vl/activity/saved-searchMessage Nikolay Yankov...
|
NULL
|
-3626554664062371282
|
NULL
|
click
|
ocr
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpAPPDOCKER• ₴1D SlackFileEditViewGoHistoryWindowHelpAPPDOCKER• ₴1DEV (-zsh)₴82app/Jobs/Crm/MatchActivityCrmData.phpapp/Jobs/Middleware/HandleHubspotRateLimit.phpAPP (-zst47++++++p42++++++*app/Mcp/Servers/JiminnyServer.phpapp/Mcp/Tools/GetMeTool.php157++++++•app/Models/Feature/FeatureEnum.phpapp/Services/Activity/HubSpot/ProviderResolver.php+-app/Services/Activity/HubSpot/ProviderResolverInterface.phpapp/Services/Activity/HubSpot/Providers/Provider.phpapp/Services/Activity/HubSpot/Providers/ProviderKixie.php+-app/Services/Activity/HubSpot/Providers/Provider0rum.phpapp/Services/Activity/HubSpot/Providers/ProviderTwilio.phpapp/Services/Activity/HubSpot/Providers/ProviderTwilioFlex.phpapp/Services/Activity/HubSpot/Service.phpapp/Services/Crm/Hubspot/Client.phpapp/Services/Crm/Hubspot/HubspotClientInterface.phpapp/Services/Crm/Hubspot/Pagination/HubspotPaginationService.phpapp/Services/Crm/Hubspot/Pagination/PaginationState.phpdatabase/migrations/2026_05_13_124153_create_mcp_feature_flag.phptests/Feature/Mcp/GetMeToolFeatureTest.phptests/Feature/Mcp/ListCallsToolFeatureTest.phptests/Feature/Mcp/McpTestHelpersTrait.phptests/Unit/Component/ES/ChunkSizeTest.phptests/Unit/Component/ES/Processor/DT0s/SelectionListTest.phptests/Unit/Component/ES/Processor/TargetEntitiesSelectorTest.phptests/Unit/Component/MeetingBot/Service/ParticipantMatcherTest.phptests/Unit/Exceptions/RateLimitExceptionTest.phptests/Unit/Jobs/Crm/MatchActivityCrmDataTest.phptests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.phptests/Unit/Services/Activity/HubSpot/ServiceTest.phptests/Unit/Services/Crm/Hubspot/ClientTest.phptests/Unit/Services/Crm/Hubspot/Pagination/HubspotPaginationServiceTest.php97++++++-132++++++•15++++++21++++--2+-25++++++.140++++++•2+-19++++++50++++++-27++++++-39++++++-6856++++++-+-151++++++-109++++++-250++++++-283++++++=37 files changed, 1587 insertions(+), 344 deletions(-)create mode 100644 app/Component/ES/ChunkSize.phpcreate mode 100644 app/Jobs/Middleware/HandleHubspotRateLimit.phpcreate mode 100644 app/Mcp/Tools/GetMeTool.phpcreate mode 100644 database/migrations/2026_05_13_124153_create_mcp_feature_flag.phpcreate mode 100644 tests/Feature/Mcp/GetMeToolFeatureTest.phpcreate mode 100644 tests/Unit/Component/ES/ChunkSizeTest.phpcreate mode 100644 tests/Unit/Exceptions/RateLimitExceptionTest.phpcreate mode 100644 tests/Unit/Jobs/Middleware/HandleHubspotRateLimitTest.phplukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (master) $ git pullAlready up to date.lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (master) $ co -b JY-20676-delete-reSwitched to a new branch 'JY-20676-delete-report-related-objects'lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20676-delete-report-related-obHomeDMsActivityFilesLaterMore> 0EDJiminny ...# Jiminny-Dg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...• Direct messages€. Vasil Vasilev8. Nikolay Yankov%. Galya Dimitrova. Aneliya Angelovaão Stefka Stoyanova. Stoyan Tomovd Todor Stamatov "Kd. Mario GeorgievNikolay Ivanovd. James Graham2 Stoyan TanevRo Steliyan GeorgievLukas Kovalik y... OAppsJira CloudToastSupport Daily • in 3 h 27 m100% <73• Tue 19 May 11:33:42Describe what you are looking forNikolay Yankov6 0MessagesAdd canvasO Files+Nikolay YankovYesterday ~имаше ли нещь . y-..-Lukas Kovalik 2:28 PMтрябва да си вързан към SF да работиNikolay Yankov 2:28 PMaxaaaNikolay Yankov 2:41 PMимаме approve на PRда го даваме за QA?Lukas Kovalik 2:42 PMдаNikolay Yankov 3:02 PMтестове фейлватрьннах го 2 пътиToday ~Nikolay Yankov 10:05 AM/api/v2/user/ask-anything-prompts?target=on_demandhas_reports/api/v2/user/ask-anything-prompts/3381a35f-f1a3-431d-9510-bd079cd80ed6DELETE/api/vl/activity/saved-searchMessage Nikolay Yankov...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
56855
|
1979
|
2
|
2026-05-19T08:33:43.226212+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179623226_m2.jpg...
|
PhpStorm
|
faVsco.js – SearchTransformer.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
PhostormVIewINavicarecodeKeractorTOOISWindowFV faV PhostormVIewINavicarecodeKeractorTOOISWindowFV faVsco.js°9 JY-20676-delete-report-related-objectsProiect v©ActivityController.php© AskAnythingController.phpUploaacontroller.ong©) ActionItemsController.pnp© ActivityController.php© AskAnythingPromptService.php© AskAnythingPrompt.phpphp api_v2.phpc) Automateakeport.png© AutomatedReportsService.phpcAicrmnotescontroller.onpC) AskAnythingPromptSer) search.phpbasecontroller.onpc) Clientl okencontroller.ono© CrmController.phpC) DealLevelPromotscontroller.phpc) DealRiskcontroller.php©)Instantmeetingcontroller.phoC) LanquageController.phpC)LavoutManagementcontroller.ohoP LiveFeedController.ohnC)Meetinascontroller.onoC) MessageController.oho C) MetadataController.oho© MobileSettingsController.phpC)MomentController.oho9) NudaeController nhn11051107Yc) NumberAllocatorControlier nhnl@ OraanizationLicensesController.php© OrganizationMembersController.php© OrganizationRetentionPolicyController© OrganizationRolesController.php© OrganizationSyncController.phpDartnerController.onp(e) DhoneNumberController.ono€ PlaybackController.php© PlaylistController.phpd) ScimController.php© SidekickController.php€ SoftphoneController.php11151114 151118c) ssocontroller.phpc) subscriptionController.php1121c)TeamalAutomationcontroller.onoC)TeamAiContextController.ono@ TeamController.ohpC) TeaminsiahtsController.ohoC) TranscriotionController.ohoC) TranslationController.onoC) UserController. ohni@ VocabularvController.ohn>M AuthTM CustomerAniM internal • D Kiosk• MTeamc@ ActivitvCantrollor nhn© AutomatedReportsController.php© DashboardController.php(e)ImnersonationController.pho115911601161final class ActivityController extends Controller implements CommentContexi aA43 M3 M10 21 AVpublic function ListActivitySearch(Request $request, SearchTransformer SsearchTransformer) : JsonResenis->response->getManager)->setSerializer(new JsonSerializerO):return Sthis->response->withCollection(suser->searches->gerssearchlranstormen->Wichlonsumer(suser)* Deletes a saved searchi* aparam Request Sreauest* doaram Search ssearch* athrows Excention• Greturn JsonResnonseDELETE /api/v1/activity/saved-search/(search} [api.saved_search.delete]nublic function deleteActivitvSpanch Renuect Snpauect Seanch Scpanch)• IcanRecnance$this->authorize( ability: 'delete', $search):// Disable and orphan any AutomatedReports that use this search$search->automatedReports->withTrashed->update(C'activity_search_id' => null"stacus → talse,1:/ Delete filters and the search itselfssearch->f1lters@->deleteo*ssearch->deleteo:return Sthis->response->w1th0korGET lapilv1/activitv/livenublic function Live(Request Srequest. FlasticActivitvRenository Srenository): JsonResnonse!...}Lxx* Gnaram Activitu SactivituThe Hunsnell nluain hac heon den.ted. If you're not writing in Hungarian, you can safely uninstall Hunspell without affecting the dictionaries for other languages. (today 10:00)= custom.log= laravel.log4 SF jiminny@localhost]4 HS_local [jiminny@localhost]& console [PROD]# console [euyA console [STAGING]© CoachingFeedbackCoachUserln.php Xstohedeclare(scrict_cypes=l)nnamespace Jiminny Component Activ1tysearch Filterderin1tion› use ...final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface29 Ф >34 0 >45 đ >-118—119135136 @t›146 C151 C=15.1usadeorivate const int No GROUP 10 = 9993 usagesorivate UserRenository suserRenository:public function__construct(UserRepository $userRepository)1...hpublic function shouldApplyQueries: boolf...}public function getQueries: FilterDefinitionQueryCollection{...hpublic function toArray: array{...hprivate function getOptions(): array{...}public function getValue®: array{...}private function getDefaultValue@: array{...}public function aetValidationRules(2strina Sorefix = null): arrav{...}public function aetSortOrder@: intf...}public function shouldBeIncluded(Team $team): bool{...}suppont Dally • In 3n 21m100% 5• Tue 19 May 11:33:43AskJiminnyReportActivityServiceTest vCascadeAsk Jiminny Report M+0 ..AskAnythingPromptService.phpInought tor osReadAskAnvthinaPromotServicelest.0no # 44-223Thought for 1sAskAnythingPromptServiceTest.php+24 -2Summarv of Revisions1. Searchtiranstormer now emits has renortslSearchTransformer.nhn. 42-50_Searchtranstormer.php:42-50public tunction transtorm(search Ssearch): arrayreturn П"Tilters = Sthis->getrilters(Ssearch),'has reports' => Ssearch->automatedReportso->existsoYou reverted the Sappends laccessor on the Search model ((correctlv — addina it would have caused unnecessary querieseverywhere the model is serialized). The flag now lives only in the transformer used by listActivitySearch.2. Rethought the prompt DTOYou're riaht - newlv-created and edited oromots will never have related reports, and most existina oromots won't have anv• Made AskAnythingPromptDto::ShasReports nullable ?bool ShasReports = null).• Onlv included it in toArravo when it is not null — same conditional pattern as ownerid / sharellsers / shareGrouos |• Removed it from create() and edit() DTO construction in AskAnythingPromptService - they always pass nothingnow. so create/undate responses won't include has renorts•In get(), it stays — calls $prompt->getHasReports() (your renamed accessor) so the list endpoint emits the flag.This way the per-row exists() auery is onlv run when the list endooint is hit. never on createledit.3. Test uodateUpdated testGetAskAnythingPrompts in AskAnythingPromptServiceTest.php to mock getHasReports() on everyoromot mock and reflect the values (one true, three false ) in the expected DTOs. The existina testCreateAskAnvthinaPromptWithTwoUsers. testEditAskAnythingPrompt. etc. don't need changes - they already construct expected DTOswithout an 8th araument. which now matches the null default.G..l..4 files +36 -4 >Accent alliAsk anvthina (884-L)<> Code Claude Qnus 1.7 MediumWN Windsurf Teams1121-28 1UTE.8io 4 spaces...
|
NULL
|
851766301850298912
|
NULL
|
click
|
ocr
|
NULL
|
PhostormVIewINavicarecodeKeractorTOOISWindowFV faV PhostormVIewINavicarecodeKeractorTOOISWindowFV faVsco.js°9 JY-20676-delete-report-related-objectsProiect v©ActivityController.php© AskAnythingController.phpUploaacontroller.ong©) ActionItemsController.pnp© ActivityController.php© AskAnythingPromptService.php© AskAnythingPrompt.phpphp api_v2.phpc) Automateakeport.png© AutomatedReportsService.phpcAicrmnotescontroller.onpC) AskAnythingPromptSer) search.phpbasecontroller.onpc) Clientl okencontroller.ono© CrmController.phpC) DealLevelPromotscontroller.phpc) DealRiskcontroller.php©)Instantmeetingcontroller.phoC) LanquageController.phpC)LavoutManagementcontroller.ohoP LiveFeedController.ohnC)Meetinascontroller.onoC) MessageController.oho C) MetadataController.oho© MobileSettingsController.phpC)MomentController.oho9) NudaeController nhn11051107Yc) NumberAllocatorControlier nhnl@ OraanizationLicensesController.php© OrganizationMembersController.php© OrganizationRetentionPolicyController© OrganizationRolesController.php© OrganizationSyncController.phpDartnerController.onp(e) DhoneNumberController.ono€ PlaybackController.php© PlaylistController.phpd) ScimController.php© SidekickController.php€ SoftphoneController.php11151114 151118c) ssocontroller.phpc) subscriptionController.php1121c)TeamalAutomationcontroller.onoC)TeamAiContextController.ono@ TeamController.ohpC) TeaminsiahtsController.ohoC) TranscriotionController.ohoC) TranslationController.onoC) UserController. ohni@ VocabularvController.ohn>M AuthTM CustomerAniM internal • D Kiosk• MTeamc@ ActivitvCantrollor nhn© AutomatedReportsController.php© DashboardController.php(e)ImnersonationController.pho115911601161final class ActivityController extends Controller implements CommentContexi aA43 M3 M10 21 AVpublic function ListActivitySearch(Request $request, SearchTransformer SsearchTransformer) : JsonResenis->response->getManager)->setSerializer(new JsonSerializerO):return Sthis->response->withCollection(suser->searches->gerssearchlranstormen->Wichlonsumer(suser)* Deletes a saved searchi* aparam Request Sreauest* doaram Search ssearch* athrows Excention• Greturn JsonResnonseDELETE /api/v1/activity/saved-search/(search} [api.saved_search.delete]nublic function deleteActivitvSpanch Renuect Snpauect Seanch Scpanch)• IcanRecnance$this->authorize( ability: 'delete', $search):// Disable and orphan any AutomatedReports that use this search$search->automatedReports->withTrashed->update(C'activity_search_id' => null"stacus → talse,1:/ Delete filters and the search itselfssearch->f1lters@->deleteo*ssearch->deleteo:return Sthis->response->w1th0korGET lapilv1/activitv/livenublic function Live(Request Srequest. FlasticActivitvRenository Srenository): JsonResnonse!...}Lxx* Gnaram Activitu SactivituThe Hunsnell nluain hac heon den.ted. If you're not writing in Hungarian, you can safely uninstall Hunspell without affecting the dictionaries for other languages. (today 10:00)= custom.log= laravel.log4 SF jiminny@localhost]4 HS_local [jiminny@localhost]& console [PROD]# console [euyA console [STAGING]© CoachingFeedbackCoachUserln.php Xstohedeclare(scrict_cypes=l)nnamespace Jiminny Component Activ1tysearch Filterderin1tion› use ...final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface29 Ф >34 0 >45 đ >-118—119135136 @t›146 C151 C=15.1usadeorivate const int No GROUP 10 = 9993 usagesorivate UserRenository suserRenository:public function__construct(UserRepository $userRepository)1...hpublic function shouldApplyQueries: boolf...}public function getQueries: FilterDefinitionQueryCollection{...hpublic function toArray: array{...hprivate function getOptions(): array{...}public function getValue®: array{...}private function getDefaultValue@: array{...}public function aetValidationRules(2strina Sorefix = null): arrav{...}public function aetSortOrder@: intf...}public function shouldBeIncluded(Team $team): bool{...}suppont Dally • In 3n 21m100% 5• Tue 19 May 11:33:43AskJiminnyReportActivityServiceTest vCascadeAsk Jiminny Report M+0 ..AskAnythingPromptService.phpInought tor osReadAskAnvthinaPromotServicelest.0no # 44-223Thought for 1sAskAnythingPromptServiceTest.php+24 -2Summarv of Revisions1. Searchtiranstormer now emits has renortslSearchTransformer.nhn. 42-50_Searchtranstormer.php:42-50public tunction transtorm(search Ssearch): arrayreturn П"Tilters = Sthis->getrilters(Ssearch),'has reports' => Ssearch->automatedReportso->existsoYou reverted the Sappends laccessor on the Search model ((correctlv — addina it would have caused unnecessary querieseverywhere the model is serialized). The flag now lives only in the transformer used by listActivitySearch.2. Rethought the prompt DTOYou're riaht - newlv-created and edited oromots will never have related reports, and most existina oromots won't have anv• Made AskAnythingPromptDto::ShasReports nullable ?bool ShasReports = null).• Onlv included it in toArravo when it is not null — same conditional pattern as ownerid / sharellsers / shareGrouos |• Removed it from create() and edit() DTO construction in AskAnythingPromptService - they always pass nothingnow. so create/undate responses won't include has renorts•In get(), it stays — calls $prompt->getHasReports() (your renamed accessor) so the list endpoint emits the flag.This way the per-row exists() auery is onlv run when the list endooint is hit. never on createledit.3. Test uodateUpdated testGetAskAnythingPrompts in AskAnythingPromptServiceTest.php to mock getHasReports() on everyoromot mock and reflect the values (one true, three false ) in the expected DTOs. The existina testCreateAskAnvthinaPromptWithTwoUsers. testEditAskAnythingPrompt. etc. don't need changes - they already construct expected DTOswithout an 8th araument. which now matches the null default.G..l..4 files +36 -4 >Accent alliAsk anvthina (884-L)<> Code Claude Qnus 1.7 MediumWN Windsurf Teams1121-28 1UTE.8io 4 spaces...
|
56853
|
NULL
|
NULL
|
NULL
|
|
56856
|
1979
|
3
|
2026-05-19T08:33:45.401195+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179625401_m2.jpg...
|
PhpStorm
|
faVsco.js – SearchTransformer.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
<?php
namespace Jiminny\Http\Transformers;
use Illuminate\Support\LazyCollection;
use Jiminny\Component;
use Jiminny\Component\ActivitySearch\Service\ActivitySearch;
use Jiminny\Exceptions\OutOfBoundsException;
use Jiminny\Component\Nudge\Http\Transformer\NudgeTransformer;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\User;
use League\Fractal;
use League\Fractal\TransformerAbstract;
use Psr\Log\LoggerInterface;
class SearchTransformer extends TransformerAbstract
{
protected array $availableIncludes = [
'nudges',
];
protected array $defaultIncludes = [
'nudges',
];
private User $consumer;
public function __construct(
private readonly ActivitySearch $activitySearch,
private readonly NudgeTransformer $nudgeTransformer,
private readonly LoggerInterface $logger,
) {
}
public function withConsumer(User $user): self
{
$this->consumer = $user;
return $this;
}
public function transform(Search $search): array
{
return [
'id' => $search->id_string,
'name' => $search->getName(),
'filters' => $this->getFilters($search),
'has_reports' => $search->automatedReports()->exists(),
];
}
public function includeNudges(Search $search): Fractal\Resource\Collection
{
return $this->collection($search->getNudges(), $this->nudgeTransformer);
}
public function getFilters(Search $search): array
{
$filterSet = $this->activitySearch->getOnDemandPageFilters()
->withConsumer($this->consumer);
$propertyTypes = $filterSet->getPropertyTypes();
$allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();
/** @var LazyCollection<int, SearchFilter> $searchFilters */
$searchFilters = $search->getFilters();
$preProcessed = [];
foreach ($searchFilters as $searchFilter) {
$filterValue = $searchFilter->getFilterValue();
$filterProperty = $searchFilter->getFilterProperty();
if (! $propertyTypes->has($filterProperty)) {
$this->logger->debug(__METHOD__ . ': unsupported property', [
'property' => $filterProperty,
'available' => $propertyTypes->keys()->all(),
]);
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
continue;
}
if (! $allowedFilters->has($filterProperty)) {
continue;
}
/** @var string $propertyType */
$propertyType = $propertyTypes->get($filterProperty);
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {
if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {
$preProcessed[$searchFilter->getFilterProperty()] = [];
}
$preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;
continue;
}
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {
$filterValue = (int) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {
$filterValue = (float) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {
$filterValue = (int) $filterValue;
} elseif ($propertyType !== Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {
throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));
}
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
}
return $preProcessed;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.098071806,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Http\\Transformers;\n\nuse Illuminate\\Support\\LazyCollection;\nuse Jiminny\\Component;\nuse Jiminny\\Component\\ActivitySearch\\Service\\ActivitySearch;\nuse Jiminny\\Exceptions\\OutOfBoundsException;\nuse Jiminny\\Component\\Nudge\\Http\\Transformer\\NudgeTransformer;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\User;\nuse League\\Fractal;\nuse League\\Fractal\\TransformerAbstract;\nuse Psr\\Log\\LoggerInterface;\n\nclass SearchTransformer extends TransformerAbstract\n{\n protected array $availableIncludes = [\n 'nudges',\n ];\n\n protected array $defaultIncludes = [\n 'nudges',\n ];\n private User $consumer;\n\n public function __construct(\n private readonly ActivitySearch $activitySearch,\n private readonly NudgeTransformer $nudgeTransformer,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n public function withConsumer(User $user): self\n {\n $this->consumer = $user;\n\n return $this;\n }\n\n public function transform(Search $search): array\n {\n return [\n 'id' => $search->id_string,\n 'name' => $search->getName(),\n 'filters' => $this->getFilters($search),\n 'has_reports' => $search->automatedReports()->exists(),\n ];\n }\n\n public function includeNudges(Search $search): Fractal\\Resource\\Collection\n {\n return $this->collection($search->getNudges(), $this->nudgeTransformer);\n }\n\n public function getFilters(Search $search): array\n {\n $filterSet = $this->activitySearch->getOnDemandPageFilters()\n ->withConsumer($this->consumer);\n\n $propertyTypes = $filterSet->getPropertyTypes();\n $allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();\n\n /** @var LazyCollection<int, SearchFilter> $searchFilters */\n $searchFilters = $search->getFilters();\n\n $preProcessed = [];\n\n foreach ($searchFilters as $searchFilter) {\n $filterValue = $searchFilter->getFilterValue();\n $filterProperty = $searchFilter->getFilterProperty();\n\n if (! $propertyTypes->has($filterProperty)) {\n $this->logger->debug(__METHOD__ . ': unsupported property', [\n 'property' => $filterProperty,\n 'available' => $propertyTypes->keys()->all(),\n ]);\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n\n continue;\n }\n\n if (! $allowedFilters->has($filterProperty)) {\n continue;\n }\n\n /** @var string $propertyType */\n $propertyType = $propertyTypes->get($filterProperty);\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {\n if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {\n $preProcessed[$searchFilter->getFilterProperty()] = [];\n }\n\n $preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;\n\n continue;\n }\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {\n $filterValue = (float) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType !== Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {\n throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));\n }\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n }\n\n return $preProcessed;\n }\n}","depth":4,"bounds":{"left":0.15990691,"top":0.083798885,"width":0.26728722,"height":0.8954509},"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Http\\Transformers;\n\nuse Illuminate\\Support\\LazyCollection;\nuse Jiminny\\Component;\nuse Jiminny\\Component\\ActivitySearch\\Service\\ActivitySearch;\nuse Jiminny\\Exceptions\\OutOfBoundsException;\nuse Jiminny\\Component\\Nudge\\Http\\Transformer\\NudgeTransformer;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\User;\nuse League\\Fractal;\nuse League\\Fractal\\TransformerAbstract;\nuse Psr\\Log\\LoggerInterface;\n\nclass SearchTransformer extends TransformerAbstract\n{\n protected array $availableIncludes = [\n 'nudges',\n ];\n\n protected array $defaultIncludes = [\n 'nudges',\n ];\n private User $consumer;\n\n public function __construct(\n private readonly ActivitySearch $activitySearch,\n private readonly NudgeTransformer $nudgeTransformer,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n public function withConsumer(User $user): self\n {\n $this->consumer = $user;\n\n return $this;\n }\n\n public function transform(Search $search): array\n {\n return [\n 'id' => $search->id_string,\n 'name' => $search->getName(),\n 'filters' => $this->getFilters($search),\n 'has_reports' => $search->automatedReports()->exists(),\n ];\n }\n\n public function includeNudges(Search $search): Fractal\\Resource\\Collection\n {\n return $this->collection($search->getNudges(), $this->nudgeTransformer);\n }\n\n public function getFilters(Search $search): array\n {\n $filterSet = $this->activitySearch->getOnDemandPageFilters()\n ->withConsumer($this->consumer);\n\n $propertyTypes = $filterSet->getPropertyTypes();\n $allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();\n\n /** @var LazyCollection<int, SearchFilter> $searchFilters */\n $searchFilters = $search->getFilters();\n\n $preProcessed = [];\n\n foreach ($searchFilters as $searchFilter) {\n $filterValue = $searchFilter->getFilterValue();\n $filterProperty = $searchFilter->getFilterProperty();\n\n if (! $propertyTypes->has($filterProperty)) {\n $this->logger->debug(__METHOD__ . ': unsupported property', [\n 'property' => $filterProperty,\n 'available' => $propertyTypes->keys()->all(),\n ]);\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n\n continue;\n }\n\n if (! $allowedFilters->has($filterProperty)) {\n continue;\n }\n\n /** @var string $propertyType */\n $propertyType = $propertyTypes->get($filterProperty);\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {\n if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {\n $preProcessed[$searchFilter->getFilterProperty()] = [];\n }\n\n $preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;\n\n continue;\n }\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {\n $filterValue = (float) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType !== Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {\n throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));\n }\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n }\n\n return $preProcessed;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.7124335,"top":0.10055866,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.72140956,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7287234,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"bounds":{"left":0.4481383,"top":0.09736632,"width":0.29288563,"height":0.8818835},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
5097404468722564493
|
-7764681655831613635
|
visual_change
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
<?php
namespace Jiminny\Http\Transformers;
use Illuminate\Support\LazyCollection;
use Jiminny\Component;
use Jiminny\Component\ActivitySearch\Service\ActivitySearch;
use Jiminny\Exceptions\OutOfBoundsException;
use Jiminny\Component\Nudge\Http\Transformer\NudgeTransformer;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\User;
use League\Fractal;
use League\Fractal\TransformerAbstract;
use Psr\Log\LoggerInterface;
class SearchTransformer extends TransformerAbstract
{
protected array $availableIncludes = [
'nudges',
];
protected array $defaultIncludes = [
'nudges',
];
private User $consumer;
public function __construct(
private readonly ActivitySearch $activitySearch,
private readonly NudgeTransformer $nudgeTransformer,
private readonly LoggerInterface $logger,
) {
}
public function withConsumer(User $user): self
{
$this->consumer = $user;
return $this;
}
public function transform(Search $search): array
{
return [
'id' => $search->id_string,
'name' => $search->getName(),
'filters' => $this->getFilters($search),
'has_reports' => $search->automatedReports()->exists(),
];
}
public function includeNudges(Search $search): Fractal\Resource\Collection
{
return $this->collection($search->getNudges(), $this->nudgeTransformer);
}
public function getFilters(Search $search): array
{
$filterSet = $this->activitySearch->getOnDemandPageFilters()
->withConsumer($this->consumer);
$propertyTypes = $filterSet->getPropertyTypes();
$allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();
/** @var LazyCollection<int, SearchFilter> $searchFilters */
$searchFilters = $search->getFilters();
$preProcessed = [];
foreach ($searchFilters as $searchFilter) {
$filterValue = $searchFilter->getFilterValue();
$filterProperty = $searchFilter->getFilterProperty();
if (! $propertyTypes->has($filterProperty)) {
$this->logger->debug(__METHOD__ . ': unsupported property', [
'property' => $filterProperty,
'available' => $propertyTypes->keys()->all(),
]);
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
continue;
}
if (! $allowedFilters->has($filterProperty)) {
continue;
}
/** @var string $propertyType */
$propertyType = $propertyTypes->get($filterProperty);
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {
if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {
$preProcessed[$searchFilter->getFilterProperty()] = [];
}
$preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;
continue;
}
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {
$filterValue = (int) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {
$filterValue = (float) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {
$filterValue = (int) $filterValue;
} elseif ($propertyType !== Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {
throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));
}
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
}
return $preProcessed;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
56857
|
1978
|
2
|
2026-05-19T08:34:14.370973+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179654370_m1.jpg...
|
PhpStorm
|
faVsco.js – SearchTransformer.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
<?php
namespace Jiminny\Http\Transformers;
use Illuminate\Support\LazyCollection;
use Jiminny\Component;
use Jiminny\Component\ActivitySearch\Service\ActivitySearch;
use Jiminny\Exceptions\OutOfBoundsException;
use Jiminny\Component\Nudge\Http\Transformer\NudgeTransformer;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\User;
use League\Fractal;
use League\Fractal\TransformerAbstract;
use Psr\Log\LoggerInterface;
class SearchTransformer extends TransformerAbstract
{
protected array $availableIncludes = [
'nudges',
];
protected array $defaultIncludes = [
'nudges',
];
private User $consumer;
public function __construct(
private readonly ActivitySearch $activitySearch,
private readonly NudgeTransformer $nudgeTransformer,
private readonly LoggerInterface $logger,
) {
}
public function withConsumer(User $user): self
{
$this->consumer = $user;
return $this;
}
public function transform(Search $search): array
{
return [
'id' => $search->id_string,
'name' => $search->getName(),
'filters' => $this->getFilters($search),
'has_reports' => $search->automatedReports()->exists(),
];
}
public function includeNudges(Search $search): Fractal\Resource\Collection
{
return $this->collection($search->getNudges(), $this->nudgeTransformer);
}
public function getFilters(Search $search): array
{
$filterSet = $this->activitySearch->getOnDemandPageFilters()
->withConsumer($this->consumer);
$propertyTypes = $filterSet->getPropertyTypes();
$allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();
/** @var LazyCollection<int, SearchFilter> $searchFilters */
$searchFilters = $search->getFilters();
$preProcessed = [];
foreach ($searchFilters as $searchFilter) {
$filterValue = $searchFilter->getFilterValue();
$filterProperty = $searchFilter->getFilterProperty();
if (! $propertyTypes->has($filterProperty)) {
$this->logger->debug(__METHOD__ . ': unsupported property', [
'property' => $filterProperty,
'available' => $propertyTypes->keys()->all(),
]);
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
continue;
}
if (! $allowedFilters->has($filterProperty)) {
continue;
}
/** @var string $propertyType */
$propertyType = $propertyTypes->get($filterProperty);
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {
if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {
$preProcessed[$searchFilter->getFilterProperty()] = [];
}
$preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;
continue;
}
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {
$filterValue = (int) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {
$filterValue = (float) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {
$filterValue = (int) $filterValue;
} elseif ($propertyType !== Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {
throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));
}
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
}
return $preProcessed;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Http\\Transformers;\n\nuse Illuminate\\Support\\LazyCollection;\nuse Jiminny\\Component;\nuse Jiminny\\Component\\ActivitySearch\\Service\\ActivitySearch;\nuse Jiminny\\Exceptions\\OutOfBoundsException;\nuse Jiminny\\Component\\Nudge\\Http\\Transformer\\NudgeTransformer;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\User;\nuse League\\Fractal;\nuse League\\Fractal\\TransformerAbstract;\nuse Psr\\Log\\LoggerInterface;\n\nclass SearchTransformer extends TransformerAbstract\n{\n protected array $availableIncludes = [\n 'nudges',\n ];\n\n protected array $defaultIncludes = [\n 'nudges',\n ];\n private User $consumer;\n\n public function __construct(\n private readonly ActivitySearch $activitySearch,\n private readonly NudgeTransformer $nudgeTransformer,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n public function withConsumer(User $user): self\n {\n $this->consumer = $user;\n\n return $this;\n }\n\n public function transform(Search $search): array\n {\n return [\n 'id' => $search->id_string,\n 'name' => $search->getName(),\n 'filters' => $this->getFilters($search),\n 'has_reports' => $search->automatedReports()->exists(),\n ];\n }\n\n public function includeNudges(Search $search): Fractal\\Resource\\Collection\n {\n return $this->collection($search->getNudges(), $this->nudgeTransformer);\n }\n\n public function getFilters(Search $search): array\n {\n $filterSet = $this->activitySearch->getOnDemandPageFilters()\n ->withConsumer($this->consumer);\n\n $propertyTypes = $filterSet->getPropertyTypes();\n $allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();\n\n /** @var LazyCollection<int, SearchFilter> $searchFilters */\n $searchFilters = $search->getFilters();\n\n $preProcessed = [];\n\n foreach ($searchFilters as $searchFilter) {\n $filterValue = $searchFilter->getFilterValue();\n $filterProperty = $searchFilter->getFilterProperty();\n\n if (! $propertyTypes->has($filterProperty)) {\n $this->logger->debug(__METHOD__ . ': unsupported property', [\n 'property' => $filterProperty,\n 'available' => $propertyTypes->keys()->all(),\n ]);\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n\n continue;\n }\n\n if (! $allowedFilters->has($filterProperty)) {\n continue;\n }\n\n /** @var string $propertyType */\n $propertyType = $propertyTypes->get($filterProperty);\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {\n if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {\n $preProcessed[$searchFilter->getFilterProperty()] = [];\n }\n\n $preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;\n\n continue;\n }\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {\n $filterValue = (float) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType !== Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {\n throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));\n }\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n }\n\n return $preProcessed;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Http\\Transformers;\n\nuse Illuminate\\Support\\LazyCollection;\nuse Jiminny\\Component;\nuse Jiminny\\Component\\ActivitySearch\\Service\\ActivitySearch;\nuse Jiminny\\Exceptions\\OutOfBoundsException;\nuse Jiminny\\Component\\Nudge\\Http\\Transformer\\NudgeTransformer;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\User;\nuse League\\Fractal;\nuse League\\Fractal\\TransformerAbstract;\nuse Psr\\Log\\LoggerInterface;\n\nclass SearchTransformer extends TransformerAbstract\n{\n protected array $availableIncludes = [\n 'nudges',\n ];\n\n protected array $defaultIncludes = [\n 'nudges',\n ];\n private User $consumer;\n\n public function __construct(\n private readonly ActivitySearch $activitySearch,\n private readonly NudgeTransformer $nudgeTransformer,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n public function withConsumer(User $user): self\n {\n $this->consumer = $user;\n\n return $this;\n }\n\n public function transform(Search $search): array\n {\n return [\n 'id' => $search->id_string,\n 'name' => $search->getName(),\n 'filters' => $this->getFilters($search),\n 'has_reports' => $search->automatedReports()->exists(),\n ];\n }\n\n public function includeNudges(Search $search): Fractal\\Resource\\Collection\n {\n return $this->collection($search->getNudges(), $this->nudgeTransformer);\n }\n\n public function getFilters(Search $search): array\n {\n $filterSet = $this->activitySearch->getOnDemandPageFilters()\n ->withConsumer($this->consumer);\n\n $propertyTypes = $filterSet->getPropertyTypes();\n $allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();\n\n /** @var LazyCollection<int, SearchFilter> $searchFilters */\n $searchFilters = $search->getFilters();\n\n $preProcessed = [];\n\n foreach ($searchFilters as $searchFilter) {\n $filterValue = $searchFilter->getFilterValue();\n $filterProperty = $searchFilter->getFilterProperty();\n\n if (! $propertyTypes->has($filterProperty)) {\n $this->logger->debug(__METHOD__ . ': unsupported property', [\n 'property' => $filterProperty,\n 'available' => $propertyTypes->keys()->all(),\n ]);\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n\n continue;\n }\n\n if (! $allowedFilters->has($filterProperty)) {\n continue;\n }\n\n /** @var string $propertyType */\n $propertyType = $propertyTypes->get($filterProperty);\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {\n if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {\n $preProcessed[$searchFilter->getFilterProperty()] = [];\n }\n\n $preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;\n\n continue;\n }\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {\n $filterValue = (float) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType !== Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {\n throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));\n }\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n }\n\n return $preProcessed;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
5097404468722564493
|
-7764681655831613635
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
<?php
namespace Jiminny\Http\Transformers;
use Illuminate\Support\LazyCollection;
use Jiminny\Component;
use Jiminny\Component\ActivitySearch\Service\ActivitySearch;
use Jiminny\Exceptions\OutOfBoundsException;
use Jiminny\Component\Nudge\Http\Transformer\NudgeTransformer;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\User;
use League\Fractal;
use League\Fractal\TransformerAbstract;
use Psr\Log\LoggerInterface;
class SearchTransformer extends TransformerAbstract
{
protected array $availableIncludes = [
'nudges',
];
protected array $defaultIncludes = [
'nudges',
];
private User $consumer;
public function __construct(
private readonly ActivitySearch $activitySearch,
private readonly NudgeTransformer $nudgeTransformer,
private readonly LoggerInterface $logger,
) {
}
public function withConsumer(User $user): self
{
$this->consumer = $user;
return $this;
}
public function transform(Search $search): array
{
return [
'id' => $search->id_string,
'name' => $search->getName(),
'filters' => $this->getFilters($search),
'has_reports' => $search->automatedReports()->exists(),
];
}
public function includeNudges(Search $search): Fractal\Resource\Collection
{
return $this->collection($search->getNudges(), $this->nudgeTransformer);
}
public function getFilters(Search $search): array
{
$filterSet = $this->activitySearch->getOnDemandPageFilters()
->withConsumer($this->consumer);
$propertyTypes = $filterSet->getPropertyTypes();
$allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();
/** @var LazyCollection<int, SearchFilter> $searchFilters */
$searchFilters = $search->getFilters();
$preProcessed = [];
foreach ($searchFilters as $searchFilter) {
$filterValue = $searchFilter->getFilterValue();
$filterProperty = $searchFilter->getFilterProperty();
if (! $propertyTypes->has($filterProperty)) {
$this->logger->debug(__METHOD__ . ': unsupported property', [
'property' => $filterProperty,
'available' => $propertyTypes->keys()->all(),
]);
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
continue;
}
if (! $allowedFilters->has($filterProperty)) {
continue;
}
/** @var string $propertyType */
$propertyType = $propertyTypes->get($filterProperty);
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {
if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {
$preProcessed[$searchFilter->getFilterProperty()] = [];
}
$preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;
continue;
}
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {
$filterValue = (int) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {
$filterValue = (float) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {
$filterValue = (int) $filterValue;
} elseif ($propertyType !== Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {
throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));
}
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
}
return $preProcessed;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56854
|
NULL
|
NULL
|
NULL
|
|
56858
|
1979
|
4
|
2026-05-19T08:34:15.709651+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179655709_m2.jpg...
|
PhpStorm
|
faVsco.js – SearchTransformer.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
<?php
namespace Jiminny\Http\Transformers;
use Illuminate\Support\LazyCollection;
use Jiminny\Component;
use Jiminny\Component\ActivitySearch\Service\ActivitySearch;
use Jiminny\Exceptions\OutOfBoundsException;
use Jiminny\Component\Nudge\Http\Transformer\NudgeTransformer;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\User;
use League\Fractal;
use League\Fractal\TransformerAbstract;
use Psr\Log\LoggerInterface;
class SearchTransformer extends TransformerAbstract
{
protected array $availableIncludes = [
'nudges',
];
protected array $defaultIncludes = [
'nudges',
];
private User $consumer;
public function __construct(
private readonly ActivitySearch $activitySearch,
private readonly NudgeTransformer $nudgeTransformer,
private readonly LoggerInterface $logger,
) {
}
public function withConsumer(User $user): self
{
$this->consumer = $user;
return $this;
}
public function transform(Search $search): array
{
return [
'id' => $search->id_string,
'name' => $search->getName(),
'filters' => $this->getFilters($search),
'has_reports' => $search->automatedReports()->exists(),
];
}
public function includeNudges(Search $search): Fractal\Resource\Collection
{
return $this->collection($search->getNudges(), $this->nudgeTransformer);
}
public function getFilters(Search $search): array
{
$filterSet = $this->activitySearch->getOnDemandPageFilters()
->withConsumer($this->consumer);
$propertyTypes = $filterSet->getPropertyTypes();
$allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();
/** @var LazyCollection<int, SearchFilter> $searchFilters */
$searchFilters = $search->getFilters();
$preProcessed = [];
foreach ($searchFilters as $searchFilter) {
$filterValue = $searchFilter->getFilterValue();
$filterProperty = $searchFilter->getFilterProperty();
if (! $propertyTypes->has($filterProperty)) {
$this->logger->debug(__METHOD__ . ': unsupported property', [
'property' => $filterProperty,
'available' => $propertyTypes->keys()->all(),
]);
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
continue;
}
if (! $allowedFilters->has($filterProperty)) {
continue;
}
/** @var string $propertyType */
$propertyType = $propertyTypes->get($filterProperty);
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {
if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {
$preProcessed[$searchFilter->getFilterProperty()] = [];
}
$preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;
continue;
}
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {
$filterValue = (int) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {
$filterValue = (float) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {
$filterValue = (int) $filterValue;
} elseif ($propertyType !== Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {
throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));
}
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
}
return $preProcessed;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.098071806,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Http\\Transformers;\n\nuse Illuminate\\Support\\LazyCollection;\nuse Jiminny\\Component;\nuse Jiminny\\Component\\ActivitySearch\\Service\\ActivitySearch;\nuse Jiminny\\Exceptions\\OutOfBoundsException;\nuse Jiminny\\Component\\Nudge\\Http\\Transformer\\NudgeTransformer;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\User;\nuse League\\Fractal;\nuse League\\Fractal\\TransformerAbstract;\nuse Psr\\Log\\LoggerInterface;\n\nclass SearchTransformer extends TransformerAbstract\n{\n protected array $availableIncludes = [\n 'nudges',\n ];\n\n protected array $defaultIncludes = [\n 'nudges',\n ];\n private User $consumer;\n\n public function __construct(\n private readonly ActivitySearch $activitySearch,\n private readonly NudgeTransformer $nudgeTransformer,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n public function withConsumer(User $user): self\n {\n $this->consumer = $user;\n\n return $this;\n }\n\n public function transform(Search $search): array\n {\n return [\n 'id' => $search->id_string,\n 'name' => $search->getName(),\n 'filters' => $this->getFilters($search),\n 'has_reports' => $search->automatedReports()->exists(),\n ];\n }\n\n public function includeNudges(Search $search): Fractal\\Resource\\Collection\n {\n return $this->collection($search->getNudges(), $this->nudgeTransformer);\n }\n\n public function getFilters(Search $search): array\n {\n $filterSet = $this->activitySearch->getOnDemandPageFilters()\n ->withConsumer($this->consumer);\n\n $propertyTypes = $filterSet->getPropertyTypes();\n $allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();\n\n /** @var LazyCollection<int, SearchFilter> $searchFilters */\n $searchFilters = $search->getFilters();\n\n $preProcessed = [];\n\n foreach ($searchFilters as $searchFilter) {\n $filterValue = $searchFilter->getFilterValue();\n $filterProperty = $searchFilter->getFilterProperty();\n\n if (! $propertyTypes->has($filterProperty)) {\n $this->logger->debug(__METHOD__ . ': unsupported property', [\n 'property' => $filterProperty,\n 'available' => $propertyTypes->keys()->all(),\n ]);\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n\n continue;\n }\n\n if (! $allowedFilters->has($filterProperty)) {\n continue;\n }\n\n /** @var string $propertyType */\n $propertyType = $propertyTypes->get($filterProperty);\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {\n if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {\n $preProcessed[$searchFilter->getFilterProperty()] = [];\n }\n\n $preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;\n\n continue;\n }\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {\n $filterValue = (float) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType !== Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {\n throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));\n }\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n }\n\n return $preProcessed;\n }\n}","depth":4,"bounds":{"left":0.15990691,"top":0.083798885,"width":0.26728722,"height":0.8954509},"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Http\\Transformers;\n\nuse Illuminate\\Support\\LazyCollection;\nuse Jiminny\\Component;\nuse Jiminny\\Component\\ActivitySearch\\Service\\ActivitySearch;\nuse Jiminny\\Exceptions\\OutOfBoundsException;\nuse Jiminny\\Component\\Nudge\\Http\\Transformer\\NudgeTransformer;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\User;\nuse League\\Fractal;\nuse League\\Fractal\\TransformerAbstract;\nuse Psr\\Log\\LoggerInterface;\n\nclass SearchTransformer extends TransformerAbstract\n{\n protected array $availableIncludes = [\n 'nudges',\n ];\n\n protected array $defaultIncludes = [\n 'nudges',\n ];\n private User $consumer;\n\n public function __construct(\n private readonly ActivitySearch $activitySearch,\n private readonly NudgeTransformer $nudgeTransformer,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n public function withConsumer(User $user): self\n {\n $this->consumer = $user;\n\n return $this;\n }\n\n public function transform(Search $search): array\n {\n return [\n 'id' => $search->id_string,\n 'name' => $search->getName(),\n 'filters' => $this->getFilters($search),\n 'has_reports' => $search->automatedReports()->exists(),\n ];\n }\n\n public function includeNudges(Search $search): Fractal\\Resource\\Collection\n {\n return $this->collection($search->getNudges(), $this->nudgeTransformer);\n }\n\n public function getFilters(Search $search): array\n {\n $filterSet = $this->activitySearch->getOnDemandPageFilters()\n ->withConsumer($this->consumer);\n\n $propertyTypes = $filterSet->getPropertyTypes();\n $allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();\n\n /** @var LazyCollection<int, SearchFilter> $searchFilters */\n $searchFilters = $search->getFilters();\n\n $preProcessed = [];\n\n foreach ($searchFilters as $searchFilter) {\n $filterValue = $searchFilter->getFilterValue();\n $filterProperty = $searchFilter->getFilterProperty();\n\n if (! $propertyTypes->has($filterProperty)) {\n $this->logger->debug(__METHOD__ . ': unsupported property', [\n 'property' => $filterProperty,\n 'available' => $propertyTypes->keys()->all(),\n ]);\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n\n continue;\n }\n\n if (! $allowedFilters->has($filterProperty)) {\n continue;\n }\n\n /** @var string $propertyType */\n $propertyType = $propertyTypes->get($filterProperty);\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {\n if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {\n $preProcessed[$searchFilter->getFilterProperty()] = [];\n }\n\n $preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;\n\n continue;\n }\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {\n $filterValue = (float) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType !== Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {\n throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));\n }\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n }\n\n return $preProcessed;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.7124335,"top":0.10055866,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.72140956,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7287234,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"bounds":{"left":0.4481383,"top":0.09736632,"width":0.29288563,"height":0.8818835},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
5097404468722564493
|
-7764681655831613635
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
<?php
namespace Jiminny\Http\Transformers;
use Illuminate\Support\LazyCollection;
use Jiminny\Component;
use Jiminny\Component\ActivitySearch\Service\ActivitySearch;
use Jiminny\Exceptions\OutOfBoundsException;
use Jiminny\Component\Nudge\Http\Transformer\NudgeTransformer;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\User;
use League\Fractal;
use League\Fractal\TransformerAbstract;
use Psr\Log\LoggerInterface;
class SearchTransformer extends TransformerAbstract
{
protected array $availableIncludes = [
'nudges',
];
protected array $defaultIncludes = [
'nudges',
];
private User $consumer;
public function __construct(
private readonly ActivitySearch $activitySearch,
private readonly NudgeTransformer $nudgeTransformer,
private readonly LoggerInterface $logger,
) {
}
public function withConsumer(User $user): self
{
$this->consumer = $user;
return $this;
}
public function transform(Search $search): array
{
return [
'id' => $search->id_string,
'name' => $search->getName(),
'filters' => $this->getFilters($search),
'has_reports' => $search->automatedReports()->exists(),
];
}
public function includeNudges(Search $search): Fractal\Resource\Collection
{
return $this->collection($search->getNudges(), $this->nudgeTransformer);
}
public function getFilters(Search $search): array
{
$filterSet = $this->activitySearch->getOnDemandPageFilters()
->withConsumer($this->consumer);
$propertyTypes = $filterSet->getPropertyTypes();
$allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();
/** @var LazyCollection<int, SearchFilter> $searchFilters */
$searchFilters = $search->getFilters();
$preProcessed = [];
foreach ($searchFilters as $searchFilter) {
$filterValue = $searchFilter->getFilterValue();
$filterProperty = $searchFilter->getFilterProperty();
if (! $propertyTypes->has($filterProperty)) {
$this->logger->debug(__METHOD__ . ': unsupported property', [
'property' => $filterProperty,
'available' => $propertyTypes->keys()->all(),
]);
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
continue;
}
if (! $allowedFilters->has($filterProperty)) {
continue;
}
/** @var string $propertyType */
$propertyType = $propertyTypes->get($filterProperty);
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {
if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {
$preProcessed[$searchFilter->getFilterProperty()] = [];
}
$preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;
continue;
}
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {
$filterValue = (int) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {
$filterValue = (float) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {
$filterValue = (int) $filterValue;
} elseif ($propertyType !== Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {
throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));
}
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
}
return $preProcessed;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56856
|
NULL
|
NULL
|
NULL
|
|
56859
|
1978
|
3
|
2026-05-19T08:34:44.600091+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179684600_m1.jpg...
|
PhpStorm
|
faVsco.js – SearchTransformer.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
<?php
namespace Jiminny\Http\Transformers;
use Illuminate\Support\LazyCollection;
use Jiminny\Component;
use Jiminny\Component\ActivitySearch\Service\ActivitySearch;
use Jiminny\Exceptions\OutOfBoundsException;
use Jiminny\Component\Nudge\Http\Transformer\NudgeTransformer;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\User;
use League\Fractal;
use League\Fractal\TransformerAbstract;
use Psr\Log\LoggerInterface;
class SearchTransformer extends TransformerAbstract
{
protected array $availableIncludes = [
'nudges',
];
protected array $defaultIncludes = [
'nudges',
];
private User $consumer;
public function __construct(
private readonly ActivitySearch $activitySearch,
private readonly NudgeTransformer $nudgeTransformer,
private readonly LoggerInterface $logger,
) {
}
public function withConsumer(User $user): self
{
$this->consumer = $user;
return $this;
}
public function transform(Search $search): array
{
return [
'id' => $search->id_string,
'name' => $search->getName(),
'filters' => $this->getFilters($search),
'has_reports' => $search->automatedReports()->exists(),
];
}
public function includeNudges(Search $search): Fractal\Resource\Collection
{
return $this->collection($search->getNudges(), $this->nudgeTransformer);
}
public function getFilters(Search $search): array
{
$filterSet = $this->activitySearch->getOnDemandPageFilters()
->withConsumer($this->consumer);
$propertyTypes = $filterSet->getPropertyTypes();
$allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();
/** @var LazyCollection<int, SearchFilter> $searchFilters */
$searchFilters = $search->getFilters();
$preProcessed = [];
foreach ($searchFilters as $searchFilter) {
$filterValue = $searchFilter->getFilterValue();
$filterProperty = $searchFilter->getFilterProperty();
if (! $propertyTypes->has($filterProperty)) {
$this->logger->debug(__METHOD__ . ': unsupported property', [
'property' => $filterProperty,
'available' => $propertyTypes->keys()->all(),
]);
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
continue;
}
if (! $allowedFilters->has($filterProperty)) {
continue;
}
/** @var string $propertyType */
$propertyType = $propertyTypes->get($filterProperty);
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {
if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {
$preProcessed[$searchFilter->getFilterProperty()] = [];
}
$preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;
continue;
}
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {
$filterValue = (int) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {
$filterValue = (float) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {
$filterValue = (int) $filterValue;
} elseif ($propertyType !== Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {
throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));
}
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
}
return $preProcessed;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Http\\Transformers;\n\nuse Illuminate\\Support\\LazyCollection;\nuse Jiminny\\Component;\nuse Jiminny\\Component\\ActivitySearch\\Service\\ActivitySearch;\nuse Jiminny\\Exceptions\\OutOfBoundsException;\nuse Jiminny\\Component\\Nudge\\Http\\Transformer\\NudgeTransformer;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\User;\nuse League\\Fractal;\nuse League\\Fractal\\TransformerAbstract;\nuse Psr\\Log\\LoggerInterface;\n\nclass SearchTransformer extends TransformerAbstract\n{\n protected array $availableIncludes = [\n 'nudges',\n ];\n\n protected array $defaultIncludes = [\n 'nudges',\n ];\n private User $consumer;\n\n public function __construct(\n private readonly ActivitySearch $activitySearch,\n private readonly NudgeTransformer $nudgeTransformer,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n public function withConsumer(User $user): self\n {\n $this->consumer = $user;\n\n return $this;\n }\n\n public function transform(Search $search): array\n {\n return [\n 'id' => $search->id_string,\n 'name' => $search->getName(),\n 'filters' => $this->getFilters($search),\n 'has_reports' => $search->automatedReports()->exists(),\n ];\n }\n\n public function includeNudges(Search $search): Fractal\\Resource\\Collection\n {\n return $this->collection($search->getNudges(), $this->nudgeTransformer);\n }\n\n public function getFilters(Search $search): array\n {\n $filterSet = $this->activitySearch->getOnDemandPageFilters()\n ->withConsumer($this->consumer);\n\n $propertyTypes = $filterSet->getPropertyTypes();\n $allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();\n\n /** @var LazyCollection<int, SearchFilter> $searchFilters */\n $searchFilters = $search->getFilters();\n\n $preProcessed = [];\n\n foreach ($searchFilters as $searchFilter) {\n $filterValue = $searchFilter->getFilterValue();\n $filterProperty = $searchFilter->getFilterProperty();\n\n if (! $propertyTypes->has($filterProperty)) {\n $this->logger->debug(__METHOD__ . ': unsupported property', [\n 'property' => $filterProperty,\n 'available' => $propertyTypes->keys()->all(),\n ]);\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n\n continue;\n }\n\n if (! $allowedFilters->has($filterProperty)) {\n continue;\n }\n\n /** @var string $propertyType */\n $propertyType = $propertyTypes->get($filterProperty);\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {\n if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {\n $preProcessed[$searchFilter->getFilterProperty()] = [];\n }\n\n $preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;\n\n continue;\n }\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {\n $filterValue = (float) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType !== Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {\n throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));\n }\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n }\n\n return $preProcessed;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Http\\Transformers;\n\nuse Illuminate\\Support\\LazyCollection;\nuse Jiminny\\Component;\nuse Jiminny\\Component\\ActivitySearch\\Service\\ActivitySearch;\nuse Jiminny\\Exceptions\\OutOfBoundsException;\nuse Jiminny\\Component\\Nudge\\Http\\Transformer\\NudgeTransformer;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\User;\nuse League\\Fractal;\nuse League\\Fractal\\TransformerAbstract;\nuse Psr\\Log\\LoggerInterface;\n\nclass SearchTransformer extends TransformerAbstract\n{\n protected array $availableIncludes = [\n 'nudges',\n ];\n\n protected array $defaultIncludes = [\n 'nudges',\n ];\n private User $consumer;\n\n public function __construct(\n private readonly ActivitySearch $activitySearch,\n private readonly NudgeTransformer $nudgeTransformer,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n public function withConsumer(User $user): self\n {\n $this->consumer = $user;\n\n return $this;\n }\n\n public function transform(Search $search): array\n {\n return [\n 'id' => $search->id_string,\n 'name' => $search->getName(),\n 'filters' => $this->getFilters($search),\n 'has_reports' => $search->automatedReports()->exists(),\n ];\n }\n\n public function includeNudges(Search $search): Fractal\\Resource\\Collection\n {\n return $this->collection($search->getNudges(), $this->nudgeTransformer);\n }\n\n public function getFilters(Search $search): array\n {\n $filterSet = $this->activitySearch->getOnDemandPageFilters()\n ->withConsumer($this->consumer);\n\n $propertyTypes = $filterSet->getPropertyTypes();\n $allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();\n\n /** @var LazyCollection<int, SearchFilter> $searchFilters */\n $searchFilters = $search->getFilters();\n\n $preProcessed = [];\n\n foreach ($searchFilters as $searchFilter) {\n $filterValue = $searchFilter->getFilterValue();\n $filterProperty = $searchFilter->getFilterProperty();\n\n if (! $propertyTypes->has($filterProperty)) {\n $this->logger->debug(__METHOD__ . ': unsupported property', [\n 'property' => $filterProperty,\n 'available' => $propertyTypes->keys()->all(),\n ]);\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n\n continue;\n }\n\n if (! $allowedFilters->has($filterProperty)) {\n continue;\n }\n\n /** @var string $propertyType */\n $propertyType = $propertyTypes->get($filterProperty);\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {\n if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {\n $preProcessed[$searchFilter->getFilterProperty()] = [];\n }\n\n $preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;\n\n continue;\n }\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {\n $filterValue = (float) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType !== Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {\n throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));\n }\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n }\n\n return $preProcessed;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
5097404468722564493
|
-7764681655831613635
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
<?php
namespace Jiminny\Http\Transformers;
use Illuminate\Support\LazyCollection;
use Jiminny\Component;
use Jiminny\Component\ActivitySearch\Service\ActivitySearch;
use Jiminny\Exceptions\OutOfBoundsException;
use Jiminny\Component\Nudge\Http\Transformer\NudgeTransformer;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\User;
use League\Fractal;
use League\Fractal\TransformerAbstract;
use Psr\Log\LoggerInterface;
class SearchTransformer extends TransformerAbstract
{
protected array $availableIncludes = [
'nudges',
];
protected array $defaultIncludes = [
'nudges',
];
private User $consumer;
public function __construct(
private readonly ActivitySearch $activitySearch,
private readonly NudgeTransformer $nudgeTransformer,
private readonly LoggerInterface $logger,
) {
}
public function withConsumer(User $user): self
{
$this->consumer = $user;
return $this;
}
public function transform(Search $search): array
{
return [
'id' => $search->id_string,
'name' => $search->getName(),
'filters' => $this->getFilters($search),
'has_reports' => $search->automatedReports()->exists(),
];
}
public function includeNudges(Search $search): Fractal\Resource\Collection
{
return $this->collection($search->getNudges(), $this->nudgeTransformer);
}
public function getFilters(Search $search): array
{
$filterSet = $this->activitySearch->getOnDemandPageFilters()
->withConsumer($this->consumer);
$propertyTypes = $filterSet->getPropertyTypes();
$allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();
/** @var LazyCollection<int, SearchFilter> $searchFilters */
$searchFilters = $search->getFilters();
$preProcessed = [];
foreach ($searchFilters as $searchFilter) {
$filterValue = $searchFilter->getFilterValue();
$filterProperty = $searchFilter->getFilterProperty();
if (! $propertyTypes->has($filterProperty)) {
$this->logger->debug(__METHOD__ . ': unsupported property', [
'property' => $filterProperty,
'available' => $propertyTypes->keys()->all(),
]);
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
continue;
}
if (! $allowedFilters->has($filterProperty)) {
continue;
}
/** @var string $propertyType */
$propertyType = $propertyTypes->get($filterProperty);
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {
if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {
$preProcessed[$searchFilter->getFilterProperty()] = [];
}
$preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;
continue;
}
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {
$filterValue = (int) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {
$filterValue = (float) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {
$filterValue = (int) $filterValue;
} elseif ($propertyType !== Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {
throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));
}
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
}
return $preProcessed;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
56860
|
1979
|
5
|
2026-05-19T08:34:45.998575+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179685998_m2.jpg...
|
PhpStorm
|
faVsco.js – SearchTransformer.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
<?php
namespace Jiminny\Http\Transformers;
use Illuminate\Support\LazyCollection;
use Jiminny\Component;
use Jiminny\Component\ActivitySearch\Service\ActivitySearch;
use Jiminny\Exceptions\OutOfBoundsException;
use Jiminny\Component\Nudge\Http\Transformer\NudgeTransformer;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\User;
use League\Fractal;
use League\Fractal\TransformerAbstract;
use Psr\Log\LoggerInterface;
class SearchTransformer extends TransformerAbstract
{
protected array $availableIncludes = [
'nudges',
];
protected array $defaultIncludes = [
'nudges',
];
private User $consumer;
public function __construct(
private readonly ActivitySearch $activitySearch,
private readonly NudgeTransformer $nudgeTransformer,
private readonly LoggerInterface $logger,
) {
}
public function withConsumer(User $user): self
{
$this->consumer = $user;
return $this;
}
public function transform(Search $search): array
{
return [
'id' => $search->id_string,
'name' => $search->getName(),
'filters' => $this->getFilters($search),
'has_reports' => $search->automatedReports()->exists(),
];
}
public function includeNudges(Search $search): Fractal\Resource\Collection
{
return $this->collection($search->getNudges(), $this->nudgeTransformer);
}
public function getFilters(Search $search): array
{
$filterSet = $this->activitySearch->getOnDemandPageFilters()
->withConsumer($this->consumer);
$propertyTypes = $filterSet->getPropertyTypes();
$allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();
/** @var LazyCollection<int, SearchFilter> $searchFilters */
$searchFilters = $search->getFilters();
$preProcessed = [];
foreach ($searchFilters as $searchFilter) {
$filterValue = $searchFilter->getFilterValue();
$filterProperty = $searchFilter->getFilterProperty();
if (! $propertyTypes->has($filterProperty)) {
$this->logger->debug(__METHOD__ . ': unsupported property', [
'property' => $filterProperty,
'available' => $propertyTypes->keys()->all(),
]);
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
continue;
}
if (! $allowedFilters->has($filterProperty)) {
continue;
}
/** @var string $propertyType */
$propertyType = $propertyTypes->get($filterProperty);
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {
if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {
$preProcessed[$searchFilter->getFilterProperty()] = [];
}
$preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;
continue;
}
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {
$filterValue = (int) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {
$filterValue = (float) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {
$filterValue = (int) $filterValue;
} elseif ($propertyType !== Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {
throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));
}
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
}
return $preProcessed;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.098071806,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Http\\Transformers;\n\nuse Illuminate\\Support\\LazyCollection;\nuse Jiminny\\Component;\nuse Jiminny\\Component\\ActivitySearch\\Service\\ActivitySearch;\nuse Jiminny\\Exceptions\\OutOfBoundsException;\nuse Jiminny\\Component\\Nudge\\Http\\Transformer\\NudgeTransformer;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\User;\nuse League\\Fractal;\nuse League\\Fractal\\TransformerAbstract;\nuse Psr\\Log\\LoggerInterface;\n\nclass SearchTransformer extends TransformerAbstract\n{\n protected array $availableIncludes = [\n 'nudges',\n ];\n\n protected array $defaultIncludes = [\n 'nudges',\n ];\n private User $consumer;\n\n public function __construct(\n private readonly ActivitySearch $activitySearch,\n private readonly NudgeTransformer $nudgeTransformer,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n public function withConsumer(User $user): self\n {\n $this->consumer = $user;\n\n return $this;\n }\n\n public function transform(Search $search): array\n {\n return [\n 'id' => $search->id_string,\n 'name' => $search->getName(),\n 'filters' => $this->getFilters($search),\n 'has_reports' => $search->automatedReports()->exists(),\n ];\n }\n\n public function includeNudges(Search $search): Fractal\\Resource\\Collection\n {\n return $this->collection($search->getNudges(), $this->nudgeTransformer);\n }\n\n public function getFilters(Search $search): array\n {\n $filterSet = $this->activitySearch->getOnDemandPageFilters()\n ->withConsumer($this->consumer);\n\n $propertyTypes = $filterSet->getPropertyTypes();\n $allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();\n\n /** @var LazyCollection<int, SearchFilter> $searchFilters */\n $searchFilters = $search->getFilters();\n\n $preProcessed = [];\n\n foreach ($searchFilters as $searchFilter) {\n $filterValue = $searchFilter->getFilterValue();\n $filterProperty = $searchFilter->getFilterProperty();\n\n if (! $propertyTypes->has($filterProperty)) {\n $this->logger->debug(__METHOD__ . ': unsupported property', [\n 'property' => $filterProperty,\n 'available' => $propertyTypes->keys()->all(),\n ]);\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n\n continue;\n }\n\n if (! $allowedFilters->has($filterProperty)) {\n continue;\n }\n\n /** @var string $propertyType */\n $propertyType = $propertyTypes->get($filterProperty);\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {\n if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {\n $preProcessed[$searchFilter->getFilterProperty()] = [];\n }\n\n $preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;\n\n continue;\n }\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {\n $filterValue = (float) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType !== Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {\n throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));\n }\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n }\n\n return $preProcessed;\n }\n}","depth":4,"bounds":{"left":0.15990691,"top":0.083798885,"width":0.26728722,"height":0.8954509},"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Http\\Transformers;\n\nuse Illuminate\\Support\\LazyCollection;\nuse Jiminny\\Component;\nuse Jiminny\\Component\\ActivitySearch\\Service\\ActivitySearch;\nuse Jiminny\\Exceptions\\OutOfBoundsException;\nuse Jiminny\\Component\\Nudge\\Http\\Transformer\\NudgeTransformer;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\User;\nuse League\\Fractal;\nuse League\\Fractal\\TransformerAbstract;\nuse Psr\\Log\\LoggerInterface;\n\nclass SearchTransformer extends TransformerAbstract\n{\n protected array $availableIncludes = [\n 'nudges',\n ];\n\n protected array $defaultIncludes = [\n 'nudges',\n ];\n private User $consumer;\n\n public function __construct(\n private readonly ActivitySearch $activitySearch,\n private readonly NudgeTransformer $nudgeTransformer,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n public function withConsumer(User $user): self\n {\n $this->consumer = $user;\n\n return $this;\n }\n\n public function transform(Search $search): array\n {\n return [\n 'id' => $search->id_string,\n 'name' => $search->getName(),\n 'filters' => $this->getFilters($search),\n 'has_reports' => $search->automatedReports()->exists(),\n ];\n }\n\n public function includeNudges(Search $search): Fractal\\Resource\\Collection\n {\n return $this->collection($search->getNudges(), $this->nudgeTransformer);\n }\n\n public function getFilters(Search $search): array\n {\n $filterSet = $this->activitySearch->getOnDemandPageFilters()\n ->withConsumer($this->consumer);\n\n $propertyTypes = $filterSet->getPropertyTypes();\n $allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();\n\n /** @var LazyCollection<int, SearchFilter> $searchFilters */\n $searchFilters = $search->getFilters();\n\n $preProcessed = [];\n\n foreach ($searchFilters as $searchFilter) {\n $filterValue = $searchFilter->getFilterValue();\n $filterProperty = $searchFilter->getFilterProperty();\n\n if (! $propertyTypes->has($filterProperty)) {\n $this->logger->debug(__METHOD__ . ': unsupported property', [\n 'property' => $filterProperty,\n 'available' => $propertyTypes->keys()->all(),\n ]);\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n\n continue;\n }\n\n if (! $allowedFilters->has($filterProperty)) {\n continue;\n }\n\n /** @var string $propertyType */\n $propertyType = $propertyTypes->get($filterProperty);\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {\n if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {\n $preProcessed[$searchFilter->getFilterProperty()] = [];\n }\n\n $preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;\n\n continue;\n }\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {\n $filterValue = (float) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType !== Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {\n throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));\n }\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n }\n\n return $preProcessed;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.7124335,"top":0.10055866,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.72140956,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7287234,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"bounds":{"left":0.4481383,"top":0.09736632,"width":0.29288563,"height":0.8818835},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
5097404468722564493
|
-7764681655831613635
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
<?php
namespace Jiminny\Http\Transformers;
use Illuminate\Support\LazyCollection;
use Jiminny\Component;
use Jiminny\Component\ActivitySearch\Service\ActivitySearch;
use Jiminny\Exceptions\OutOfBoundsException;
use Jiminny\Component\Nudge\Http\Transformer\NudgeTransformer;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\User;
use League\Fractal;
use League\Fractal\TransformerAbstract;
use Psr\Log\LoggerInterface;
class SearchTransformer extends TransformerAbstract
{
protected array $availableIncludes = [
'nudges',
];
protected array $defaultIncludes = [
'nudges',
];
private User $consumer;
public function __construct(
private readonly ActivitySearch $activitySearch,
private readonly NudgeTransformer $nudgeTransformer,
private readonly LoggerInterface $logger,
) {
}
public function withConsumer(User $user): self
{
$this->consumer = $user;
return $this;
}
public function transform(Search $search): array
{
return [
'id' => $search->id_string,
'name' => $search->getName(),
'filters' => $this->getFilters($search),
'has_reports' => $search->automatedReports()->exists(),
];
}
public function includeNudges(Search $search): Fractal\Resource\Collection
{
return $this->collection($search->getNudges(), $this->nudgeTransformer);
}
public function getFilters(Search $search): array
{
$filterSet = $this->activitySearch->getOnDemandPageFilters()
->withConsumer($this->consumer);
$propertyTypes = $filterSet->getPropertyTypes();
$allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();
/** @var LazyCollection<int, SearchFilter> $searchFilters */
$searchFilters = $search->getFilters();
$preProcessed = [];
foreach ($searchFilters as $searchFilter) {
$filterValue = $searchFilter->getFilterValue();
$filterProperty = $searchFilter->getFilterProperty();
if (! $propertyTypes->has($filterProperty)) {
$this->logger->debug(__METHOD__ . ': unsupported property', [
'property' => $filterProperty,
'available' => $propertyTypes->keys()->all(),
]);
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
continue;
}
if (! $allowedFilters->has($filterProperty)) {
continue;
}
/** @var string $propertyType */
$propertyType = $propertyTypes->get($filterProperty);
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {
if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {
$preProcessed[$searchFilter->getFilterProperty()] = [];
}
$preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;
continue;
}
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {
$filterValue = (int) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {
$filterValue = (float) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {
$filterValue = (int) $filterValue;
} elseif ($propertyType !== Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {
throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));
}
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
}
return $preProcessed;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56856
|
NULL
|
NULL
|
NULL
|
|
56861
|
1978
|
4
|
2026-05-19T08:35:14.849694+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179714849_m1.jpg...
|
PhpStorm
|
faVsco.js – SearchTransformer.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
<?php
namespace Jiminny\Http\Transformers;
use Illuminate\Support\LazyCollection;
use Jiminny\Component;
use Jiminny\Component\ActivitySearch\Service\ActivitySearch;
use Jiminny\Exceptions\OutOfBoundsException;
use Jiminny\Component\Nudge\Http\Transformer\NudgeTransformer;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\User;
use League\Fractal;
use League\Fractal\TransformerAbstract;
use Psr\Log\LoggerInterface;
class SearchTransformer extends TransformerAbstract
{
protected array $availableIncludes = [
'nudges',
];
protected array $defaultIncludes = [
'nudges',
];
private User $consumer;
public function __construct(
private readonly ActivitySearch $activitySearch,
private readonly NudgeTransformer $nudgeTransformer,
private readonly LoggerInterface $logger,
) {
}
public function withConsumer(User $user): self
{
$this->consumer = $user;
return $this;
}
public function transform(Search $search): array
{
return [
'id' => $search->id_string,
'name' => $search->getName(),
'filters' => $this->getFilters($search),
'has_reports' => $search->automatedReports()->exists(),
];
}
public function includeNudges(Search $search): Fractal\Resource\Collection
{
return $this->collection($search->getNudges(), $this->nudgeTransformer);
}
public function getFilters(Search $search): array
{
$filterSet = $this->activitySearch->getOnDemandPageFilters()
->withConsumer($this->consumer);
$propertyTypes = $filterSet->getPropertyTypes();
$allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();
/** @var LazyCollection<int, SearchFilter> $searchFilters */
$searchFilters = $search->getFilters();
$preProcessed = [];
foreach ($searchFilters as $searchFilter) {
$filterValue = $searchFilter->getFilterValue();
$filterProperty = $searchFilter->getFilterProperty();
if (! $propertyTypes->has($filterProperty)) {
$this->logger->debug(__METHOD__ . ': unsupported property', [
'property' => $filterProperty,
'available' => $propertyTypes->keys()->all(),
]);
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
continue;
}
if (! $allowedFilters->has($filterProperty)) {
continue;
}
/** @var string $propertyType */
$propertyType = $propertyTypes->get($filterProperty);
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {
if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {
$preProcessed[$searchFilter->getFilterProperty()] = [];
}
$preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;
continue;
}
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {
$filterValue = (int) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {
$filterValue = (float) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {
$filterValue = (int) $filterValue;
} elseif ($propertyType !== Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {
throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));
}
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
}
return $preProcessed;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Http\\Transformers;\n\nuse Illuminate\\Support\\LazyCollection;\nuse Jiminny\\Component;\nuse Jiminny\\Component\\ActivitySearch\\Service\\ActivitySearch;\nuse Jiminny\\Exceptions\\OutOfBoundsException;\nuse Jiminny\\Component\\Nudge\\Http\\Transformer\\NudgeTransformer;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\User;\nuse League\\Fractal;\nuse League\\Fractal\\TransformerAbstract;\nuse Psr\\Log\\LoggerInterface;\n\nclass SearchTransformer extends TransformerAbstract\n{\n protected array $availableIncludes = [\n 'nudges',\n ];\n\n protected array $defaultIncludes = [\n 'nudges',\n ];\n private User $consumer;\n\n public function __construct(\n private readonly ActivitySearch $activitySearch,\n private readonly NudgeTransformer $nudgeTransformer,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n public function withConsumer(User $user): self\n {\n $this->consumer = $user;\n\n return $this;\n }\n\n public function transform(Search $search): array\n {\n return [\n 'id' => $search->id_string,\n 'name' => $search->getName(),\n 'filters' => $this->getFilters($search),\n 'has_reports' => $search->automatedReports()->exists(),\n ];\n }\n\n public function includeNudges(Search $search): Fractal\\Resource\\Collection\n {\n return $this->collection($search->getNudges(), $this->nudgeTransformer);\n }\n\n public function getFilters(Search $search): array\n {\n $filterSet = $this->activitySearch->getOnDemandPageFilters()\n ->withConsumer($this->consumer);\n\n $propertyTypes = $filterSet->getPropertyTypes();\n $allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();\n\n /** @var LazyCollection<int, SearchFilter> $searchFilters */\n $searchFilters = $search->getFilters();\n\n $preProcessed = [];\n\n foreach ($searchFilters as $searchFilter) {\n $filterValue = $searchFilter->getFilterValue();\n $filterProperty = $searchFilter->getFilterProperty();\n\n if (! $propertyTypes->has($filterProperty)) {\n $this->logger->debug(__METHOD__ . ': unsupported property', [\n 'property' => $filterProperty,\n 'available' => $propertyTypes->keys()->all(),\n ]);\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n\n continue;\n }\n\n if (! $allowedFilters->has($filterProperty)) {\n continue;\n }\n\n /** @var string $propertyType */\n $propertyType = $propertyTypes->get($filterProperty);\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {\n if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {\n $preProcessed[$searchFilter->getFilterProperty()] = [];\n }\n\n $preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;\n\n continue;\n }\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {\n $filterValue = (float) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType !== Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {\n throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));\n }\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n }\n\n return $preProcessed;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Http\\Transformers;\n\nuse Illuminate\\Support\\LazyCollection;\nuse Jiminny\\Component;\nuse Jiminny\\Component\\ActivitySearch\\Service\\ActivitySearch;\nuse Jiminny\\Exceptions\\OutOfBoundsException;\nuse Jiminny\\Component\\Nudge\\Http\\Transformer\\NudgeTransformer;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\User;\nuse League\\Fractal;\nuse League\\Fractal\\TransformerAbstract;\nuse Psr\\Log\\LoggerInterface;\n\nclass SearchTransformer extends TransformerAbstract\n{\n protected array $availableIncludes = [\n 'nudges',\n ];\n\n protected array $defaultIncludes = [\n 'nudges',\n ];\n private User $consumer;\n\n public function __construct(\n private readonly ActivitySearch $activitySearch,\n private readonly NudgeTransformer $nudgeTransformer,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n public function withConsumer(User $user): self\n {\n $this->consumer = $user;\n\n return $this;\n }\n\n public function transform(Search $search): array\n {\n return [\n 'id' => $search->id_string,\n 'name' => $search->getName(),\n 'filters' => $this->getFilters($search),\n 'has_reports' => $search->automatedReports()->exists(),\n ];\n }\n\n public function includeNudges(Search $search): Fractal\\Resource\\Collection\n {\n return $this->collection($search->getNudges(), $this->nudgeTransformer);\n }\n\n public function getFilters(Search $search): array\n {\n $filterSet = $this->activitySearch->getOnDemandPageFilters()\n ->withConsumer($this->consumer);\n\n $propertyTypes = $filterSet->getPropertyTypes();\n $allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();\n\n /** @var LazyCollection<int, SearchFilter> $searchFilters */\n $searchFilters = $search->getFilters();\n\n $preProcessed = [];\n\n foreach ($searchFilters as $searchFilter) {\n $filterValue = $searchFilter->getFilterValue();\n $filterProperty = $searchFilter->getFilterProperty();\n\n if (! $propertyTypes->has($filterProperty)) {\n $this->logger->debug(__METHOD__ . ': unsupported property', [\n 'property' => $filterProperty,\n 'available' => $propertyTypes->keys()->all(),\n ]);\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n\n continue;\n }\n\n if (! $allowedFilters->has($filterProperty)) {\n continue;\n }\n\n /** @var string $propertyType */\n $propertyType = $propertyTypes->get($filterProperty);\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {\n if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {\n $preProcessed[$searchFilter->getFilterProperty()] = [];\n }\n\n $preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;\n\n continue;\n }\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {\n $filterValue = (float) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType !== Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {\n throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));\n }\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n }\n\n return $preProcessed;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
5097404468722564493
|
-7764681655831613635
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
<?php
namespace Jiminny\Http\Transformers;
use Illuminate\Support\LazyCollection;
use Jiminny\Component;
use Jiminny\Component\ActivitySearch\Service\ActivitySearch;
use Jiminny\Exceptions\OutOfBoundsException;
use Jiminny\Component\Nudge\Http\Transformer\NudgeTransformer;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\User;
use League\Fractal;
use League\Fractal\TransformerAbstract;
use Psr\Log\LoggerInterface;
class SearchTransformer extends TransformerAbstract
{
protected array $availableIncludes = [
'nudges',
];
protected array $defaultIncludes = [
'nudges',
];
private User $consumer;
public function __construct(
private readonly ActivitySearch $activitySearch,
private readonly NudgeTransformer $nudgeTransformer,
private readonly LoggerInterface $logger,
) {
}
public function withConsumer(User $user): self
{
$this->consumer = $user;
return $this;
}
public function transform(Search $search): array
{
return [
'id' => $search->id_string,
'name' => $search->getName(),
'filters' => $this->getFilters($search),
'has_reports' => $search->automatedReports()->exists(),
];
}
public function includeNudges(Search $search): Fractal\Resource\Collection
{
return $this->collection($search->getNudges(), $this->nudgeTransformer);
}
public function getFilters(Search $search): array
{
$filterSet = $this->activitySearch->getOnDemandPageFilters()
->withConsumer($this->consumer);
$propertyTypes = $filterSet->getPropertyTypes();
$allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();
/** @var LazyCollection<int, SearchFilter> $searchFilters */
$searchFilters = $search->getFilters();
$preProcessed = [];
foreach ($searchFilters as $searchFilter) {
$filterValue = $searchFilter->getFilterValue();
$filterProperty = $searchFilter->getFilterProperty();
if (! $propertyTypes->has($filterProperty)) {
$this->logger->debug(__METHOD__ . ': unsupported property', [
'property' => $filterProperty,
'available' => $propertyTypes->keys()->all(),
]);
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
continue;
}
if (! $allowedFilters->has($filterProperty)) {
continue;
}
/** @var string $propertyType */
$propertyType = $propertyTypes->get($filterProperty);
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {
if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {
$preProcessed[$searchFilter->getFilterProperty()] = [];
}
$preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;
continue;
}
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {
$filterValue = (int) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {
$filterValue = (float) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {
$filterValue = (int) $filterValue;
} elseif ($propertyType !== Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {
throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));
}
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
}
return $preProcessed;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56859
|
NULL
|
NULL
|
NULL
|
|
56862
|
1979
|
6
|
2026-05-19T08:35:16.263666+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179716263_m2.jpg...
|
PhpStorm
|
faVsco.js – SearchTransformer.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
<?php
namespace Jiminny\Http\Transformers;
use Illuminate\Support\LazyCollection;
use Jiminny\Component;
use Jiminny\Component\ActivitySearch\Service\ActivitySearch;
use Jiminny\Exceptions\OutOfBoundsException;
use Jiminny\Component\Nudge\Http\Transformer\NudgeTransformer;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\User;
use League\Fractal;
use League\Fractal\TransformerAbstract;
use Psr\Log\LoggerInterface;
class SearchTransformer extends TransformerAbstract
{
protected array $availableIncludes = [
'nudges',
];
protected array $defaultIncludes = [
'nudges',
];
private User $consumer;
public function __construct(
private readonly ActivitySearch $activitySearch,
private readonly NudgeTransformer $nudgeTransformer,
private readonly LoggerInterface $logger,
) {
}
public function withConsumer(User $user): self
{
$this->consumer = $user;
return $this;
}
public function transform(Search $search): array
{
return [
'id' => $search->id_string,
'name' => $search->getName(),
'filters' => $this->getFilters($search),
'has_reports' => $search->automatedReports()->exists(),
];
}
public function includeNudges(Search $search): Fractal\Resource\Collection
{
return $this->collection($search->getNudges(), $this->nudgeTransformer);
}
public function getFilters(Search $search): array
{
$filterSet = $this->activitySearch->getOnDemandPageFilters()
->withConsumer($this->consumer);
$propertyTypes = $filterSet->getPropertyTypes();
$allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();
/** @var LazyCollection<int, SearchFilter> $searchFilters */
$searchFilters = $search->getFilters();
$preProcessed = [];
foreach ($searchFilters as $searchFilter) {
$filterValue = $searchFilter->getFilterValue();
$filterProperty = $searchFilter->getFilterProperty();
if (! $propertyTypes->has($filterProperty)) {
$this->logger->debug(__METHOD__ . ': unsupported property', [
'property' => $filterProperty,
'available' => $propertyTypes->keys()->all(),
]);
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
continue;
}
if (! $allowedFilters->has($filterProperty)) {
continue;
}
/** @var string $propertyType */
$propertyType = $propertyTypes->get($filterProperty);
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {
if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {
$preProcessed[$searchFilter->getFilterProperty()] = [];
}
$preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;
continue;
}
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {
$filterValue = (int) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {
$filterValue = (float) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {
$filterValue = (int) $filterValue;
} elseif ($propertyType !== Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {
throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));
}
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
}
return $preProcessed;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.098071806,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Http\\Transformers;\n\nuse Illuminate\\Support\\LazyCollection;\nuse Jiminny\\Component;\nuse Jiminny\\Component\\ActivitySearch\\Service\\ActivitySearch;\nuse Jiminny\\Exceptions\\OutOfBoundsException;\nuse Jiminny\\Component\\Nudge\\Http\\Transformer\\NudgeTransformer;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\User;\nuse League\\Fractal;\nuse League\\Fractal\\TransformerAbstract;\nuse Psr\\Log\\LoggerInterface;\n\nclass SearchTransformer extends TransformerAbstract\n{\n protected array $availableIncludes = [\n 'nudges',\n ];\n\n protected array $defaultIncludes = [\n 'nudges',\n ];\n private User $consumer;\n\n public function __construct(\n private readonly ActivitySearch $activitySearch,\n private readonly NudgeTransformer $nudgeTransformer,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n public function withConsumer(User $user): self\n {\n $this->consumer = $user;\n\n return $this;\n }\n\n public function transform(Search $search): array\n {\n return [\n 'id' => $search->id_string,\n 'name' => $search->getName(),\n 'filters' => $this->getFilters($search),\n 'has_reports' => $search->automatedReports()->exists(),\n ];\n }\n\n public function includeNudges(Search $search): Fractal\\Resource\\Collection\n {\n return $this->collection($search->getNudges(), $this->nudgeTransformer);\n }\n\n public function getFilters(Search $search): array\n {\n $filterSet = $this->activitySearch->getOnDemandPageFilters()\n ->withConsumer($this->consumer);\n\n $propertyTypes = $filterSet->getPropertyTypes();\n $allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();\n\n /** @var LazyCollection<int, SearchFilter> $searchFilters */\n $searchFilters = $search->getFilters();\n\n $preProcessed = [];\n\n foreach ($searchFilters as $searchFilter) {\n $filterValue = $searchFilter->getFilterValue();\n $filterProperty = $searchFilter->getFilterProperty();\n\n if (! $propertyTypes->has($filterProperty)) {\n $this->logger->debug(__METHOD__ . ': unsupported property', [\n 'property' => $filterProperty,\n 'available' => $propertyTypes->keys()->all(),\n ]);\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n\n continue;\n }\n\n if (! $allowedFilters->has($filterProperty)) {\n continue;\n }\n\n /** @var string $propertyType */\n $propertyType = $propertyTypes->get($filterProperty);\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {\n if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {\n $preProcessed[$searchFilter->getFilterProperty()] = [];\n }\n\n $preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;\n\n continue;\n }\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {\n $filterValue = (float) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType !== Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {\n throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));\n }\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n }\n\n return $preProcessed;\n }\n}","depth":4,"bounds":{"left":0.15990691,"top":0.083798885,"width":0.26728722,"height":0.8954509},"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Http\\Transformers;\n\nuse Illuminate\\Support\\LazyCollection;\nuse Jiminny\\Component;\nuse Jiminny\\Component\\ActivitySearch\\Service\\ActivitySearch;\nuse Jiminny\\Exceptions\\OutOfBoundsException;\nuse Jiminny\\Component\\Nudge\\Http\\Transformer\\NudgeTransformer;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\User;\nuse League\\Fractal;\nuse League\\Fractal\\TransformerAbstract;\nuse Psr\\Log\\LoggerInterface;\n\nclass SearchTransformer extends TransformerAbstract\n{\n protected array $availableIncludes = [\n 'nudges',\n ];\n\n protected array $defaultIncludes = [\n 'nudges',\n ];\n private User $consumer;\n\n public function __construct(\n private readonly ActivitySearch $activitySearch,\n private readonly NudgeTransformer $nudgeTransformer,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n public function withConsumer(User $user): self\n {\n $this->consumer = $user;\n\n return $this;\n }\n\n public function transform(Search $search): array\n {\n return [\n 'id' => $search->id_string,\n 'name' => $search->getName(),\n 'filters' => $this->getFilters($search),\n 'has_reports' => $search->automatedReports()->exists(),\n ];\n }\n\n public function includeNudges(Search $search): Fractal\\Resource\\Collection\n {\n return $this->collection($search->getNudges(), $this->nudgeTransformer);\n }\n\n public function getFilters(Search $search): array\n {\n $filterSet = $this->activitySearch->getOnDemandPageFilters()\n ->withConsumer($this->consumer);\n\n $propertyTypes = $filterSet->getPropertyTypes();\n $allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();\n\n /** @var LazyCollection<int, SearchFilter> $searchFilters */\n $searchFilters = $search->getFilters();\n\n $preProcessed = [];\n\n foreach ($searchFilters as $searchFilter) {\n $filterValue = $searchFilter->getFilterValue();\n $filterProperty = $searchFilter->getFilterProperty();\n\n if (! $propertyTypes->has($filterProperty)) {\n $this->logger->debug(__METHOD__ . ': unsupported property', [\n 'property' => $filterProperty,\n 'available' => $propertyTypes->keys()->all(),\n ]);\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n\n continue;\n }\n\n if (! $allowedFilters->has($filterProperty)) {\n continue;\n }\n\n /** @var string $propertyType */\n $propertyType = $propertyTypes->get($filterProperty);\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {\n if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {\n $preProcessed[$searchFilter->getFilterProperty()] = [];\n }\n\n $preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;\n\n continue;\n }\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {\n $filterValue = (float) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType !== Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {\n throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));\n }\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n }\n\n return $preProcessed;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.7124335,"top":0.10055866,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.72140956,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7287234,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"bounds":{"left":0.4481383,"top":0.09736632,"width":0.29288563,"height":0.8818835},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
5097404468722564493
|
-7764681655831613635
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
<?php
namespace Jiminny\Http\Transformers;
use Illuminate\Support\LazyCollection;
use Jiminny\Component;
use Jiminny\Component\ActivitySearch\Service\ActivitySearch;
use Jiminny\Exceptions\OutOfBoundsException;
use Jiminny\Component\Nudge\Http\Transformer\NudgeTransformer;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\User;
use League\Fractal;
use League\Fractal\TransformerAbstract;
use Psr\Log\LoggerInterface;
class SearchTransformer extends TransformerAbstract
{
protected array $availableIncludes = [
'nudges',
];
protected array $defaultIncludes = [
'nudges',
];
private User $consumer;
public function __construct(
private readonly ActivitySearch $activitySearch,
private readonly NudgeTransformer $nudgeTransformer,
private readonly LoggerInterface $logger,
) {
}
public function withConsumer(User $user): self
{
$this->consumer = $user;
return $this;
}
public function transform(Search $search): array
{
return [
'id' => $search->id_string,
'name' => $search->getName(),
'filters' => $this->getFilters($search),
'has_reports' => $search->automatedReports()->exists(),
];
}
public function includeNudges(Search $search): Fractal\Resource\Collection
{
return $this->collection($search->getNudges(), $this->nudgeTransformer);
}
public function getFilters(Search $search): array
{
$filterSet = $this->activitySearch->getOnDemandPageFilters()
->withConsumer($this->consumer);
$propertyTypes = $filterSet->getPropertyTypes();
$allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();
/** @var LazyCollection<int, SearchFilter> $searchFilters */
$searchFilters = $search->getFilters();
$preProcessed = [];
foreach ($searchFilters as $searchFilter) {
$filterValue = $searchFilter->getFilterValue();
$filterProperty = $searchFilter->getFilterProperty();
if (! $propertyTypes->has($filterProperty)) {
$this->logger->debug(__METHOD__ . ': unsupported property', [
'property' => $filterProperty,
'available' => $propertyTypes->keys()->all(),
]);
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
continue;
}
if (! $allowedFilters->has($filterProperty)) {
continue;
}
/** @var string $propertyType */
$propertyType = $propertyTypes->get($filterProperty);
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {
if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {
$preProcessed[$searchFilter->getFilterProperty()] = [];
}
$preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;
continue;
}
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {
$filterValue = (int) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {
$filterValue = (float) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {
$filterValue = (int) $filterValue;
} elseif ($propertyType !== Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {
throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));
}
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
}
return $preProcessed;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56856
|
NULL
|
NULL
|
NULL
|
|
56863
|
1978
|
5
|
2026-05-19T08:35:45.084099+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179745084_m1.jpg...
|
PhpStorm
|
faVsco.js – SearchTransformer.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
<?php
namespace Jiminny\Http\Transformers;
use Illuminate\Support\LazyCollection;
use Jiminny\Component;
use Jiminny\Component\ActivitySearch\Service\ActivitySearch;
use Jiminny\Exceptions\OutOfBoundsException;
use Jiminny\Component\Nudge\Http\Transformer\NudgeTransformer;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\User;
use League\Fractal;
use League\Fractal\TransformerAbstract;
use Psr\Log\LoggerInterface;
class SearchTransformer extends TransformerAbstract
{
protected array $availableIncludes = [
'nudges',
];
protected array $defaultIncludes = [
'nudges',
];
private User $consumer;
public function __construct(
private readonly ActivitySearch $activitySearch,
private readonly NudgeTransformer $nudgeTransformer,
private readonly LoggerInterface $logger,
) {
}
public function withConsumer(User $user): self
{
$this->consumer = $user;
return $this;
}
public function transform(Search $search): array
{
return [
'id' => $search->id_string,
'name' => $search->getName(),
'filters' => $this->getFilters($search),
'has_reports' => $search->automatedReports()->exists(),
];
}
public function includeNudges(Search $search): Fractal\Resource\Collection
{
return $this->collection($search->getNudges(), $this->nudgeTransformer);
}
public function getFilters(Search $search): array
{
$filterSet = $this->activitySearch->getOnDemandPageFilters()
->withConsumer($this->consumer);
$propertyTypes = $filterSet->getPropertyTypes();
$allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();
/** @var LazyCollection<int, SearchFilter> $searchFilters */
$searchFilters = $search->getFilters();
$preProcessed = [];
foreach ($searchFilters as $searchFilter) {
$filterValue = $searchFilter->getFilterValue();
$filterProperty = $searchFilter->getFilterProperty();
if (! $propertyTypes->has($filterProperty)) {
$this->logger->debug(__METHOD__ . ': unsupported property', [
'property' => $filterProperty,
'available' => $propertyTypes->keys()->all(),
]);
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
continue;
}
if (! $allowedFilters->has($filterProperty)) {
continue;
}
/** @var string $propertyType */
$propertyType = $propertyTypes->get($filterProperty);
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {
if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {
$preProcessed[$searchFilter->getFilterProperty()] = [];
}
$preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;
continue;
}
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {
$filterValue = (int) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {
$filterValue = (float) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {
$filterValue = (int) $filterValue;
} elseif ($propertyType !== Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {
throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));
}
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
}
return $preProcessed;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Http\\Transformers;\n\nuse Illuminate\\Support\\LazyCollection;\nuse Jiminny\\Component;\nuse Jiminny\\Component\\ActivitySearch\\Service\\ActivitySearch;\nuse Jiminny\\Exceptions\\OutOfBoundsException;\nuse Jiminny\\Component\\Nudge\\Http\\Transformer\\NudgeTransformer;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\User;\nuse League\\Fractal;\nuse League\\Fractal\\TransformerAbstract;\nuse Psr\\Log\\LoggerInterface;\n\nclass SearchTransformer extends TransformerAbstract\n{\n protected array $availableIncludes = [\n 'nudges',\n ];\n\n protected array $defaultIncludes = [\n 'nudges',\n ];\n private User $consumer;\n\n public function __construct(\n private readonly ActivitySearch $activitySearch,\n private readonly NudgeTransformer $nudgeTransformer,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n public function withConsumer(User $user): self\n {\n $this->consumer = $user;\n\n return $this;\n }\n\n public function transform(Search $search): array\n {\n return [\n 'id' => $search->id_string,\n 'name' => $search->getName(),\n 'filters' => $this->getFilters($search),\n 'has_reports' => $search->automatedReports()->exists(),\n ];\n }\n\n public function includeNudges(Search $search): Fractal\\Resource\\Collection\n {\n return $this->collection($search->getNudges(), $this->nudgeTransformer);\n }\n\n public function getFilters(Search $search): array\n {\n $filterSet = $this->activitySearch->getOnDemandPageFilters()\n ->withConsumer($this->consumer);\n\n $propertyTypes = $filterSet->getPropertyTypes();\n $allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();\n\n /** @var LazyCollection<int, SearchFilter> $searchFilters */\n $searchFilters = $search->getFilters();\n\n $preProcessed = [];\n\n foreach ($searchFilters as $searchFilter) {\n $filterValue = $searchFilter->getFilterValue();\n $filterProperty = $searchFilter->getFilterProperty();\n\n if (! $propertyTypes->has($filterProperty)) {\n $this->logger->debug(__METHOD__ . ': unsupported property', [\n 'property' => $filterProperty,\n 'available' => $propertyTypes->keys()->all(),\n ]);\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n\n continue;\n }\n\n if (! $allowedFilters->has($filterProperty)) {\n continue;\n }\n\n /** @var string $propertyType */\n $propertyType = $propertyTypes->get($filterProperty);\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {\n if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {\n $preProcessed[$searchFilter->getFilterProperty()] = [];\n }\n\n $preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;\n\n continue;\n }\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {\n $filterValue = (float) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType !== Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {\n throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));\n }\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n }\n\n return $preProcessed;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Http\\Transformers;\n\nuse Illuminate\\Support\\LazyCollection;\nuse Jiminny\\Component;\nuse Jiminny\\Component\\ActivitySearch\\Service\\ActivitySearch;\nuse Jiminny\\Exceptions\\OutOfBoundsException;\nuse Jiminny\\Component\\Nudge\\Http\\Transformer\\NudgeTransformer;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\User;\nuse League\\Fractal;\nuse League\\Fractal\\TransformerAbstract;\nuse Psr\\Log\\LoggerInterface;\n\nclass SearchTransformer extends TransformerAbstract\n{\n protected array $availableIncludes = [\n 'nudges',\n ];\n\n protected array $defaultIncludes = [\n 'nudges',\n ];\n private User $consumer;\n\n public function __construct(\n private readonly ActivitySearch $activitySearch,\n private readonly NudgeTransformer $nudgeTransformer,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n public function withConsumer(User $user): self\n {\n $this->consumer = $user;\n\n return $this;\n }\n\n public function transform(Search $search): array\n {\n return [\n 'id' => $search->id_string,\n 'name' => $search->getName(),\n 'filters' => $this->getFilters($search),\n 'has_reports' => $search->automatedReports()->exists(),\n ];\n }\n\n public function includeNudges(Search $search): Fractal\\Resource\\Collection\n {\n return $this->collection($search->getNudges(), $this->nudgeTransformer);\n }\n\n public function getFilters(Search $search): array\n {\n $filterSet = $this->activitySearch->getOnDemandPageFilters()\n ->withConsumer($this->consumer);\n\n $propertyTypes = $filterSet->getPropertyTypes();\n $allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();\n\n /** @var LazyCollection<int, SearchFilter> $searchFilters */\n $searchFilters = $search->getFilters();\n\n $preProcessed = [];\n\n foreach ($searchFilters as $searchFilter) {\n $filterValue = $searchFilter->getFilterValue();\n $filterProperty = $searchFilter->getFilterProperty();\n\n if (! $propertyTypes->has($filterProperty)) {\n $this->logger->debug(__METHOD__ . ': unsupported property', [\n 'property' => $filterProperty,\n 'available' => $propertyTypes->keys()->all(),\n ]);\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n\n continue;\n }\n\n if (! $allowedFilters->has($filterProperty)) {\n continue;\n }\n\n /** @var string $propertyType */\n $propertyType = $propertyTypes->get($filterProperty);\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {\n if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {\n $preProcessed[$searchFilter->getFilterProperty()] = [];\n }\n\n $preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;\n\n continue;\n }\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {\n $filterValue = (float) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType !== Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {\n throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));\n }\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n }\n\n return $preProcessed;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
5097404468722564493
|
-7764681655831613635
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
<?php
namespace Jiminny\Http\Transformers;
use Illuminate\Support\LazyCollection;
use Jiminny\Component;
use Jiminny\Component\ActivitySearch\Service\ActivitySearch;
use Jiminny\Exceptions\OutOfBoundsException;
use Jiminny\Component\Nudge\Http\Transformer\NudgeTransformer;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\User;
use League\Fractal;
use League\Fractal\TransformerAbstract;
use Psr\Log\LoggerInterface;
class SearchTransformer extends TransformerAbstract
{
protected array $availableIncludes = [
'nudges',
];
protected array $defaultIncludes = [
'nudges',
];
private User $consumer;
public function __construct(
private readonly ActivitySearch $activitySearch,
private readonly NudgeTransformer $nudgeTransformer,
private readonly LoggerInterface $logger,
) {
}
public function withConsumer(User $user): self
{
$this->consumer = $user;
return $this;
}
public function transform(Search $search): array
{
return [
'id' => $search->id_string,
'name' => $search->getName(),
'filters' => $this->getFilters($search),
'has_reports' => $search->automatedReports()->exists(),
];
}
public function includeNudges(Search $search): Fractal\Resource\Collection
{
return $this->collection($search->getNudges(), $this->nudgeTransformer);
}
public function getFilters(Search $search): array
{
$filterSet = $this->activitySearch->getOnDemandPageFilters()
->withConsumer($this->consumer);
$propertyTypes = $filterSet->getPropertyTypes();
$allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();
/** @var LazyCollection<int, SearchFilter> $searchFilters */
$searchFilters = $search->getFilters();
$preProcessed = [];
foreach ($searchFilters as $searchFilter) {
$filterValue = $searchFilter->getFilterValue();
$filterProperty = $searchFilter->getFilterProperty();
if (! $propertyTypes->has($filterProperty)) {
$this->logger->debug(__METHOD__ . ': unsupported property', [
'property' => $filterProperty,
'available' => $propertyTypes->keys()->all(),
]);
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
continue;
}
if (! $allowedFilters->has($filterProperty)) {
continue;
}
/** @var string $propertyType */
$propertyType = $propertyTypes->get($filterProperty);
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {
if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {
$preProcessed[$searchFilter->getFilterProperty()] = [];
}
$preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;
continue;
}
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {
$filterValue = (int) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {
$filterValue = (float) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {
$filterValue = (int) $filterValue;
} elseif ($propertyType !== Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {
throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));
}
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
}
return $preProcessed;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56859
|
NULL
|
NULL
|
NULL
|
|
56864
|
1979
|
7
|
2026-05-19T08:35:46.551227+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179746551_m2.jpg...
|
PhpStorm
|
faVsco.js – SearchTransformer.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
<?php
namespace Jiminny\Http\Transformers;
use Illuminate\Support\LazyCollection;
use Jiminny\Component;
use Jiminny\Component\ActivitySearch\Service\ActivitySearch;
use Jiminny\Exceptions\OutOfBoundsException;
use Jiminny\Component\Nudge\Http\Transformer\NudgeTransformer;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\User;
use League\Fractal;
use League\Fractal\TransformerAbstract;
use Psr\Log\LoggerInterface;
class SearchTransformer extends TransformerAbstract
{
protected array $availableIncludes = [
'nudges',
];
protected array $defaultIncludes = [
'nudges',
];
private User $consumer;
public function __construct(
private readonly ActivitySearch $activitySearch,
private readonly NudgeTransformer $nudgeTransformer,
private readonly LoggerInterface $logger,
) {
}
public function withConsumer(User $user): self
{
$this->consumer = $user;
return $this;
}
public function transform(Search $search): array
{
return [
'id' => $search->id_string,
'name' => $search->getName(),
'filters' => $this->getFilters($search),
'has_reports' => $search->automatedReports()->exists(),
];
}
public function includeNudges(Search $search): Fractal\Resource\Collection
{
return $this->collection($search->getNudges(), $this->nudgeTransformer);
}
public function getFilters(Search $search): array
{
$filterSet = $this->activitySearch->getOnDemandPageFilters()
->withConsumer($this->consumer);
$propertyTypes = $filterSet->getPropertyTypes();
$allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();
/** @var LazyCollection<int, SearchFilter> $searchFilters */
$searchFilters = $search->getFilters();
$preProcessed = [];
foreach ($searchFilters as $searchFilter) {
$filterValue = $searchFilter->getFilterValue();
$filterProperty = $searchFilter->getFilterProperty();
if (! $propertyTypes->has($filterProperty)) {
$this->logger->debug(__METHOD__ . ': unsupported property', [
'property' => $filterProperty,
'available' => $propertyTypes->keys()->all(),
]);
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
continue;
}
if (! $allowedFilters->has($filterProperty)) {
continue;
}
/** @var string $propertyType */
$propertyType = $propertyTypes->get($filterProperty);
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {
if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {
$preProcessed[$searchFilter->getFilterProperty()] = [];
}
$preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;
continue;
}
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {
$filterValue = (int) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {
$filterValue = (float) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {
$filterValue = (int) $filterValue;
} elseif ($propertyType !== Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {
throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));
}
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
}
return $preProcessed;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.098071806,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Http\\Transformers;\n\nuse Illuminate\\Support\\LazyCollection;\nuse Jiminny\\Component;\nuse Jiminny\\Component\\ActivitySearch\\Service\\ActivitySearch;\nuse Jiminny\\Exceptions\\OutOfBoundsException;\nuse Jiminny\\Component\\Nudge\\Http\\Transformer\\NudgeTransformer;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\User;\nuse League\\Fractal;\nuse League\\Fractal\\TransformerAbstract;\nuse Psr\\Log\\LoggerInterface;\n\nclass SearchTransformer extends TransformerAbstract\n{\n protected array $availableIncludes = [\n 'nudges',\n ];\n\n protected array $defaultIncludes = [\n 'nudges',\n ];\n private User $consumer;\n\n public function __construct(\n private readonly ActivitySearch $activitySearch,\n private readonly NudgeTransformer $nudgeTransformer,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n public function withConsumer(User $user): self\n {\n $this->consumer = $user;\n\n return $this;\n }\n\n public function transform(Search $search): array\n {\n return [\n 'id' => $search->id_string,\n 'name' => $search->getName(),\n 'filters' => $this->getFilters($search),\n 'has_reports' => $search->automatedReports()->exists(),\n ];\n }\n\n public function includeNudges(Search $search): Fractal\\Resource\\Collection\n {\n return $this->collection($search->getNudges(), $this->nudgeTransformer);\n }\n\n public function getFilters(Search $search): array\n {\n $filterSet = $this->activitySearch->getOnDemandPageFilters()\n ->withConsumer($this->consumer);\n\n $propertyTypes = $filterSet->getPropertyTypes();\n $allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();\n\n /** @var LazyCollection<int, SearchFilter> $searchFilters */\n $searchFilters = $search->getFilters();\n\n $preProcessed = [];\n\n foreach ($searchFilters as $searchFilter) {\n $filterValue = $searchFilter->getFilterValue();\n $filterProperty = $searchFilter->getFilterProperty();\n\n if (! $propertyTypes->has($filterProperty)) {\n $this->logger->debug(__METHOD__ . ': unsupported property', [\n 'property' => $filterProperty,\n 'available' => $propertyTypes->keys()->all(),\n ]);\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n\n continue;\n }\n\n if (! $allowedFilters->has($filterProperty)) {\n continue;\n }\n\n /** @var string $propertyType */\n $propertyType = $propertyTypes->get($filterProperty);\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {\n if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {\n $preProcessed[$searchFilter->getFilterProperty()] = [];\n }\n\n $preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;\n\n continue;\n }\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {\n $filterValue = (float) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType !== Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {\n throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));\n }\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n }\n\n return $preProcessed;\n }\n}","depth":4,"bounds":{"left":0.15990691,"top":0.083798885,"width":0.26728722,"height":0.8954509},"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Http\\Transformers;\n\nuse Illuminate\\Support\\LazyCollection;\nuse Jiminny\\Component;\nuse Jiminny\\Component\\ActivitySearch\\Service\\ActivitySearch;\nuse Jiminny\\Exceptions\\OutOfBoundsException;\nuse Jiminny\\Component\\Nudge\\Http\\Transformer\\NudgeTransformer;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\User;\nuse League\\Fractal;\nuse League\\Fractal\\TransformerAbstract;\nuse Psr\\Log\\LoggerInterface;\n\nclass SearchTransformer extends TransformerAbstract\n{\n protected array $availableIncludes = [\n 'nudges',\n ];\n\n protected array $defaultIncludes = [\n 'nudges',\n ];\n private User $consumer;\n\n public function __construct(\n private readonly ActivitySearch $activitySearch,\n private readonly NudgeTransformer $nudgeTransformer,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n public function withConsumer(User $user): self\n {\n $this->consumer = $user;\n\n return $this;\n }\n\n public function transform(Search $search): array\n {\n return [\n 'id' => $search->id_string,\n 'name' => $search->getName(),\n 'filters' => $this->getFilters($search),\n 'has_reports' => $search->automatedReports()->exists(),\n ];\n }\n\n public function includeNudges(Search $search): Fractal\\Resource\\Collection\n {\n return $this->collection($search->getNudges(), $this->nudgeTransformer);\n }\n\n public function getFilters(Search $search): array\n {\n $filterSet = $this->activitySearch->getOnDemandPageFilters()\n ->withConsumer($this->consumer);\n\n $propertyTypes = $filterSet->getPropertyTypes();\n $allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();\n\n /** @var LazyCollection<int, SearchFilter> $searchFilters */\n $searchFilters = $search->getFilters();\n\n $preProcessed = [];\n\n foreach ($searchFilters as $searchFilter) {\n $filterValue = $searchFilter->getFilterValue();\n $filterProperty = $searchFilter->getFilterProperty();\n\n if (! $propertyTypes->has($filterProperty)) {\n $this->logger->debug(__METHOD__ . ': unsupported property', [\n 'property' => $filterProperty,\n 'available' => $propertyTypes->keys()->all(),\n ]);\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n\n continue;\n }\n\n if (! $allowedFilters->has($filterProperty)) {\n continue;\n }\n\n /** @var string $propertyType */\n $propertyType = $propertyTypes->get($filterProperty);\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {\n if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {\n $preProcessed[$searchFilter->getFilterProperty()] = [];\n }\n\n $preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;\n\n continue;\n }\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {\n $filterValue = (float) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType !== Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {\n throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));\n }\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n }\n\n return $preProcessed;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.7124335,"top":0.10055866,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.72140956,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7287234,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"bounds":{"left":0.4481383,"top":0.09736632,"width":0.29288563,"height":0.8818835},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
5097404468722564493
|
-7764681655831613635
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
<?php
namespace Jiminny\Http\Transformers;
use Illuminate\Support\LazyCollection;
use Jiminny\Component;
use Jiminny\Component\ActivitySearch\Service\ActivitySearch;
use Jiminny\Exceptions\OutOfBoundsException;
use Jiminny\Component\Nudge\Http\Transformer\NudgeTransformer;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\User;
use League\Fractal;
use League\Fractal\TransformerAbstract;
use Psr\Log\LoggerInterface;
class SearchTransformer extends TransformerAbstract
{
protected array $availableIncludes = [
'nudges',
];
protected array $defaultIncludes = [
'nudges',
];
private User $consumer;
public function __construct(
private readonly ActivitySearch $activitySearch,
private readonly NudgeTransformer $nudgeTransformer,
private readonly LoggerInterface $logger,
) {
}
public function withConsumer(User $user): self
{
$this->consumer = $user;
return $this;
}
public function transform(Search $search): array
{
return [
'id' => $search->id_string,
'name' => $search->getName(),
'filters' => $this->getFilters($search),
'has_reports' => $search->automatedReports()->exists(),
];
}
public function includeNudges(Search $search): Fractal\Resource\Collection
{
return $this->collection($search->getNudges(), $this->nudgeTransformer);
}
public function getFilters(Search $search): array
{
$filterSet = $this->activitySearch->getOnDemandPageFilters()
->withConsumer($this->consumer);
$propertyTypes = $filterSet->getPropertyTypes();
$allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();
/** @var LazyCollection<int, SearchFilter> $searchFilters */
$searchFilters = $search->getFilters();
$preProcessed = [];
foreach ($searchFilters as $searchFilter) {
$filterValue = $searchFilter->getFilterValue();
$filterProperty = $searchFilter->getFilterProperty();
if (! $propertyTypes->has($filterProperty)) {
$this->logger->debug(__METHOD__ . ': unsupported property', [
'property' => $filterProperty,
'available' => $propertyTypes->keys()->all(),
]);
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
continue;
}
if (! $allowedFilters->has($filterProperty)) {
continue;
}
/** @var string $propertyType */
$propertyType = $propertyTypes->get($filterProperty);
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {
if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {
$preProcessed[$searchFilter->getFilterProperty()] = [];
}
$preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;
continue;
}
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {
$filterValue = (int) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {
$filterValue = (float) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {
$filterValue = (int) $filterValue;
} elseif ($propertyType !== Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {
throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));
}
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
}
return $preProcessed;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56856
|
NULL
|
NULL
|
NULL
|
|
56865
|
1978
|
6
|
2026-05-19T08:36:15.337986+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-19/1779 /Users/lukas/.screenpipe/data/data/2026-05-19/1779179775337_m1.jpg...
|
PhpStorm
|
faVsco.js – SearchTransformer.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
<?php
namespace Jiminny\Http\Transformers;
use Illuminate\Support\LazyCollection;
use Jiminny\Component;
use Jiminny\Component\ActivitySearch\Service\ActivitySearch;
use Jiminny\Exceptions\OutOfBoundsException;
use Jiminny\Component\Nudge\Http\Transformer\NudgeTransformer;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\User;
use League\Fractal;
use League\Fractal\TransformerAbstract;
use Psr\Log\LoggerInterface;
class SearchTransformer extends TransformerAbstract
{
protected array $availableIncludes = [
'nudges',
];
protected array $defaultIncludes = [
'nudges',
];
private User $consumer;
public function __construct(
private readonly ActivitySearch $activitySearch,
private readonly NudgeTransformer $nudgeTransformer,
private readonly LoggerInterface $logger,
) {
}
public function withConsumer(User $user): self
{
$this->consumer = $user;
return $this;
}
public function transform(Search $search): array
{
return [
'id' => $search->id_string,
'name' => $search->getName(),
'filters' => $this->getFilters($search),
'has_reports' => $search->automatedReports()->exists(),
];
}
public function includeNudges(Search $search): Fractal\Resource\Collection
{
return $this->collection($search->getNudges(), $this->nudgeTransformer);
}
public function getFilters(Search $search): array
{
$filterSet = $this->activitySearch->getOnDemandPageFilters()
->withConsumer($this->consumer);
$propertyTypes = $filterSet->getPropertyTypes();
$allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();
/** @var LazyCollection<int, SearchFilter> $searchFilters */
$searchFilters = $search->getFilters();
$preProcessed = [];
foreach ($searchFilters as $searchFilter) {
$filterValue = $searchFilter->getFilterValue();
$filterProperty = $searchFilter->getFilterProperty();
if (! $propertyTypes->has($filterProperty)) {
$this->logger->debug(__METHOD__ . ': unsupported property', [
'property' => $filterProperty,
'available' => $propertyTypes->keys()->all(),
]);
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
continue;
}
if (! $allowedFilters->has($filterProperty)) {
continue;
}
/** @var string $propertyType */
$propertyType = $propertyTypes->get($filterProperty);
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {
if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {
$preProcessed[$searchFilter->getFilterProperty()] = [];
}
$preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;
continue;
}
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {
$filterValue = (int) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {
$filterValue = (float) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {
$filterValue = (int) $filterValue;
} elseif ($propertyType !== Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {
throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));
}
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
}
return $preProcessed;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20676-delete-report-related-objects, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20676-delete-report-related-objects","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Http\\Transformers;\n\nuse Illuminate\\Support\\LazyCollection;\nuse Jiminny\\Component;\nuse Jiminny\\Component\\ActivitySearch\\Service\\ActivitySearch;\nuse Jiminny\\Exceptions\\OutOfBoundsException;\nuse Jiminny\\Component\\Nudge\\Http\\Transformer\\NudgeTransformer;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\User;\nuse League\\Fractal;\nuse League\\Fractal\\TransformerAbstract;\nuse Psr\\Log\\LoggerInterface;\n\nclass SearchTransformer extends TransformerAbstract\n{\n protected array $availableIncludes = [\n 'nudges',\n ];\n\n protected array $defaultIncludes = [\n 'nudges',\n ];\n private User $consumer;\n\n public function __construct(\n private readonly ActivitySearch $activitySearch,\n private readonly NudgeTransformer $nudgeTransformer,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n public function withConsumer(User $user): self\n {\n $this->consumer = $user;\n\n return $this;\n }\n\n public function transform(Search $search): array\n {\n return [\n 'id' => $search->id_string,\n 'name' => $search->getName(),\n 'filters' => $this->getFilters($search),\n 'has_reports' => $search->automatedReports()->exists(),\n ];\n }\n\n public function includeNudges(Search $search): Fractal\\Resource\\Collection\n {\n return $this->collection($search->getNudges(), $this->nudgeTransformer);\n }\n\n public function getFilters(Search $search): array\n {\n $filterSet = $this->activitySearch->getOnDemandPageFilters()\n ->withConsumer($this->consumer);\n\n $propertyTypes = $filterSet->getPropertyTypes();\n $allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();\n\n /** @var LazyCollection<int, SearchFilter> $searchFilters */\n $searchFilters = $search->getFilters();\n\n $preProcessed = [];\n\n foreach ($searchFilters as $searchFilter) {\n $filterValue = $searchFilter->getFilterValue();\n $filterProperty = $searchFilter->getFilterProperty();\n\n if (! $propertyTypes->has($filterProperty)) {\n $this->logger->debug(__METHOD__ . ': unsupported property', [\n 'property' => $filterProperty,\n 'available' => $propertyTypes->keys()->all(),\n ]);\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n\n continue;\n }\n\n if (! $allowedFilters->has($filterProperty)) {\n continue;\n }\n\n /** @var string $propertyType */\n $propertyType = $propertyTypes->get($filterProperty);\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {\n if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {\n $preProcessed[$searchFilter->getFilterProperty()] = [];\n }\n\n $preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;\n\n continue;\n }\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {\n $filterValue = (float) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType !== Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {\n throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));\n }\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n }\n\n return $preProcessed;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Http\\Transformers;\n\nuse Illuminate\\Support\\LazyCollection;\nuse Jiminny\\Component;\nuse Jiminny\\Component\\ActivitySearch\\Service\\ActivitySearch;\nuse Jiminny\\Exceptions\\OutOfBoundsException;\nuse Jiminny\\Component\\Nudge\\Http\\Transformer\\NudgeTransformer;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\Activity\\SearchFilter;\nuse Jiminny\\Models\\User;\nuse League\\Fractal;\nuse League\\Fractal\\TransformerAbstract;\nuse Psr\\Log\\LoggerInterface;\n\nclass SearchTransformer extends TransformerAbstract\n{\n protected array $availableIncludes = [\n 'nudges',\n ];\n\n protected array $defaultIncludes = [\n 'nudges',\n ];\n private User $consumer;\n\n public function __construct(\n private readonly ActivitySearch $activitySearch,\n private readonly NudgeTransformer $nudgeTransformer,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n public function withConsumer(User $user): self\n {\n $this->consumer = $user;\n\n return $this;\n }\n\n public function transform(Search $search): array\n {\n return [\n 'id' => $search->id_string,\n 'name' => $search->getName(),\n 'filters' => $this->getFilters($search),\n 'has_reports' => $search->automatedReports()->exists(),\n ];\n }\n\n public function includeNudges(Search $search): Fractal\\Resource\\Collection\n {\n return $this->collection($search->getNudges(), $this->nudgeTransformer);\n }\n\n public function getFilters(Search $search): array\n {\n $filterSet = $this->activitySearch->getOnDemandPageFilters()\n ->withConsumer($this->consumer);\n\n $propertyTypes = $filterSet->getPropertyTypes();\n $allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();\n\n /** @var LazyCollection<int, SearchFilter> $searchFilters */\n $searchFilters = $search->getFilters();\n\n $preProcessed = [];\n\n foreach ($searchFilters as $searchFilter) {\n $filterValue = $searchFilter->getFilterValue();\n $filterProperty = $searchFilter->getFilterProperty();\n\n if (! $propertyTypes->has($filterProperty)) {\n $this->logger->debug(__METHOD__ . ': unsupported property', [\n 'property' => $filterProperty,\n 'available' => $propertyTypes->keys()->all(),\n ]);\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n\n continue;\n }\n\n if (! $allowedFilters->has($filterProperty)) {\n continue;\n }\n\n /** @var string $propertyType */\n $propertyType = $propertyTypes->get($filterProperty);\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {\n if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {\n $preProcessed[$searchFilter->getFilterProperty()] = [];\n }\n\n $preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;\n\n continue;\n }\n\n if ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {\n $filterValue = (float) $filterValue;\n } elseif ($propertyType === Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {\n $filterValue = (int) $filterValue;\n } elseif ($propertyType !== Component\\ActivitySearch\\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {\n throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));\n }\n\n $preProcessed[$searchFilter->getFilterProperty()] = $filterValue;\n }\n\n return $preProcessed;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Component\\ActivitySearch\\FilterDefinition;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQuery;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinitionQueryCollection;\nuse Jiminny\\Contracts\\ActivitySearch\\ValidatedFilterDefinitionInterface;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Models;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Traits\\RequiresUUID;\nuse Elastica\\Query;\n\nfinal class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface\n{\n private const int NO_GROUP_ID = 999;\n private UserRepository $userRepository;\n\n public function __construct(UserRepository $userRepository)\n {\n $this->userRepository = $userRepository;\n }\n\n public function shouldApplyQueries(): bool\n {\n return count($this->getValue()) > 0;\n }\n\n public function getQueries(): FilterDefinitionQueryCollection\n {\n $userIds = $this->getValue();\n\n return FilterDefinitionQueryCollection::make([\n FilterDefinitionQuery::instance()\n ->setQuery(new Query\\Terms('coachingFeedbacks.coach.id_string', $userIds))\n ->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),\n ]);\n }\n\n public function toArray(): array\n {\n return [\n 'id' => 'coaching-feedback-user-filter',\n 'label' => 'Coach',\n 'helpText' => 'The person who completed the Coaching Framework',\n 'placeholder' => 'Search coaches',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'queryParam' => 'coaching_feedback_coach_id',\n 'options' => $this->getOptions(),\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'value' => $this->getValue(),\n ];\n }\n\n private function getOptions(): array\n {\n $user = $this->executedBy;\n $query = $user\n ->getTeam()\n ->users()\n ->whereNotIn(\n 'uuid',\n $this->userRepository->findInaccessibleDeactivatedUserUuids($user)\n ->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))\n ->all(),\n )\n ->orderBy('name');\n\n $users = $query\n ->with('group')\n ->get()\n ->reduce(\n static function (array $carry, Models\\User $user): array {\n $group = $user->getGroup();\n $groupId = $group !== null\n ? $group->getUuid()\n : self::NO_GROUP_ID;\n $groupName = $group !== null\n ? $group->getName()\n : '(NON-GROUPED)';\n\n if (! array_key_exists($groupId, $carry)) {\n $carry[$groupId] = [\n 'label' => $groupName,\n 'users' => [],\n ];\n }\n\n $carry[$groupId]['users'][] = [\n 'id' => $user->getUuid(),\n 'name' => sprintf(\n '%s%s',\n $user->getName(),\n ! $user->isStatusActive()\n ? ' (Inactive)'\n : ''\n ),\n ];\n\n return $carry;\n },\n []\n );\n\n return Collection::make($users)\n ->sortBy('label')\n ->values()\n ->toArray();\n }\n\n public function getValue(): array\n {\n if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {\n return $this->getDefaultValue();\n }\n\n return array_diff(\n $this->criteria->getCoachingFeedbackCoachUserId(),\n $this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),\n );\n }\n\n private function getDefaultValue(): array\n {\n return [];\n }\n\n public function getValidationRules(?string $prefix = null): array\n {\n $team = $this->executedBy->getTeam();\n\n return [\n $prefix . 'coaching_feedback_coach_id' => 'array',\n $prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),\n ];\n }\n\n public function getSortOrder(): int\n {\n return 86;\n }\n\n public function shouldBeIncluded(Team $team): bool\n {\n return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
5097404468722564493
|
-7764681655831613635
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20676-delete-report-re Project: faVsco.js, menu
JY-20676-delete-report-related-objects, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
<?php
namespace Jiminny\Http\Transformers;
use Illuminate\Support\LazyCollection;
use Jiminny\Component;
use Jiminny\Component\ActivitySearch\Service\ActivitySearch;
use Jiminny\Exceptions\OutOfBoundsException;
use Jiminny\Component\Nudge\Http\Transformer\NudgeTransformer;
use Jiminny\Models\Activity\Search;
use Jiminny\Models\Activity\SearchFilter;
use Jiminny\Models\User;
use League\Fractal;
use League\Fractal\TransformerAbstract;
use Psr\Log\LoggerInterface;
class SearchTransformer extends TransformerAbstract
{
protected array $availableIncludes = [
'nudges',
];
protected array $defaultIncludes = [
'nudges',
];
private User $consumer;
public function __construct(
private readonly ActivitySearch $activitySearch,
private readonly NudgeTransformer $nudgeTransformer,
private readonly LoggerInterface $logger,
) {
}
public function withConsumer(User $user): self
{
$this->consumer = $user;
return $this;
}
public function transform(Search $search): array
{
return [
'id' => $search->id_string,
'name' => $search->getName(),
'filters' => $this->getFilters($search),
'has_reports' => $search->automatedReports()->exists(),
];
}
public function includeNudges(Search $search): Fractal\Resource\Collection
{
return $this->collection($search->getNudges(), $this->nudgeTransformer);
}
public function getFilters(Search $search): array
{
$filterSet = $this->activitySearch->getOnDemandPageFilters()
->withConsumer($this->consumer);
$propertyTypes = $filterSet->getPropertyTypes();
$allowedFilters = $filterSet->withRestrictions($this->consumer->getTeam())->getPropertyTypes();
/** @var LazyCollection<int, SearchFilter> $searchFilters */
$searchFilters = $search->getFilters();
$preProcessed = [];
foreach ($searchFilters as $searchFilter) {
$filterValue = $searchFilter->getFilterValue();
$filterProperty = $searchFilter->getFilterProperty();
if (! $propertyTypes->has($filterProperty)) {
$this->logger->debug(__METHOD__ . ': unsupported property', [
'property' => $filterProperty,
'available' => $propertyTypes->keys()->all(),
]);
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
continue;
}
if (! $allowedFilters->has($filterProperty)) {
continue;
}
/** @var string $propertyType */
$propertyType = $propertyTypes->get($filterProperty);
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_ARRAY) {
if (! array_key_exists($searchFilter->getFilterProperty(), $preProcessed)) {
$preProcessed[$searchFilter->getFilterProperty()] = [];
}
$preProcessed[$searchFilter->getFilterProperty()][] = $filterValue;
continue;
}
if ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_INTEGER) {
$filterValue = (int) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_FLOAT) {
$filterValue = (float) $filterValue;
} elseif ($propertyType === Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_BOOLEAN) {
$filterValue = (int) $filterValue;
} elseif ($propertyType !== Component\ActivitySearch\FilterDefinitionCollection::PROPERTY_TYPE_STRING) {
throw new OutOfBoundsException(sprintf('Unknown property type: %s', $propertyType));
}
$preProcessed[$searchFilter->getFilterProperty()] = $filterValue;
}
return $preProcessed;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Component\ActivitySearch\FilterDefinition;
use Illuminate\Support\Collection;
use Jiminny\Component\ActivitySearch\FilterDefinition;
use Jiminny\Component\ActivitySearch\FilterDefinitionQuery;
use Jiminny\Component\ActivitySearch\FilterDefinitionQueryCollection;
use Jiminny\Contracts\ActivitySearch\ValidatedFilterDefinitionInterface;
use Jiminny\Contracts\Repositories\UserRepository;
use Jiminny\Models;
use Jiminny\Models\Feature\FeatureEnum;
use Jiminny\Models\Team;
use Jiminny\Traits\RequiresUUID;
use Elastica\Query;
final class CoachingFeedbackCoachUserIn extends FilterDefinition implements ValidatedFilterDefinitionInterface
{
private const int NO_GROUP_ID = 999;
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function shouldApplyQueries(): bool
{
return count($this->getValue()) > 0;
}
public function getQueries(): FilterDefinitionQueryCollection
{
$userIds = $this->getValue();
return FilterDefinitionQueryCollection::make([
FilterDefinitionQuery::instance()
->setQuery(new Query\Terms('coachingFeedbacks.coach.id_string', $userIds))
->setPath('coachingFeedbacks.coach', 'coachingFeedbacks'),
]);
}
public function toArray(): array
{
return [
'id' => 'coaching-feedback-user-filter',
'label' => 'Coach',
'helpText' => 'The person who completed the Coaching Framework',
'placeholder' => 'Search coaches',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'queryParam' => 'coaching_feedback_coach_id',
'options' => $this->getOptions(),
'groupLabelKey' => 'label',
'groupValuesKey' => 'users',
'optionLabelKey' => 'name',
'optionValueKey' => 'id',
'value' => $this->getValue(),
];
}
private function getOptions(): array
{
$user = $this->executedBy;
$query = $user
->getTeam()
->users()
->whereNotIn(
'uuid',
$this->userRepository->findInaccessibleDeactivatedUserUuids($user)
->map(static fn (string $uuid): string => RequiresUUID::toOptimized($uuid))
->all(),
)
->orderBy('name');
$users = $query
->with('group')
->get()
->reduce(
static function (array $carry, Models\User $user): array {
$group = $user->getGroup();
$groupId = $group !== null
? $group->getUuid()
: self::NO_GROUP_ID;
$groupName = $group !== null
? $group->getName()
: '(NON-GROUPED)';
if (! array_key_exists($groupId, $carry)) {
$carry[$groupId] = [
'label' => $groupName,
'users' => [],
];
}
$carry[$groupId]['users'][] = [
'id' => $user->getUuid(),
'name' => sprintf(
'%s%s',
$user->getName(),
! $user->isStatusActive()
? ' (Inactive)'
: ''
),
];
return $carry;
},
[]
);
return Collection::make($users)
->sortBy('label')
->values()
->toArray();
}
public function getValue(): array
{
if (! $this->criteria->hasCoachingFeedbackCoachUserIds()) {
return $this->getDefaultValue();
}
return array_diff(
$this->criteria->getCoachingFeedbackCoachUserId(),
$this->userRepository->findInaccessibleDeactivatedUserUuids($this->executedBy)->all(),
);
}
private function getDefaultValue(): array
{
return [];
}
public function getValidationRules(?string $prefix = null): array
{
$team = $this->executedBy->getTeam();
return [
$prefix . 'coaching_feedback_coach_id' => 'array',
$prefix . 'coaching_feedback_coach_id.*' => 'uuid:users,team_id,' . $team->getId(),
];
}
public function getSortOrder(): int
{
return 86;
}
public function shouldBeIncluded(Team $team): bool
{
return $team->hasFeature(FeatureEnum::COACHING_FRAMEWORK);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
56859
|
NULL
|
NULL
|
NULL
|